Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can you declare a variable inside an if statement

843789Jul 7 2009 — edited Jul 13 2009
I know i can do something like this in C++, but can you do it in java?
if((int i = myArray.indexOf(obj1)) > 0)
{
    //Do something with i
}
or do i HAVE to declare it outside of the IF statement?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 10 2009
Added on Jul 7 2009
24 comments
503 views