If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Ok i didn't think id make a new thread but is there a way to see if every value in an array is set? Like if i initialize an array like
int[] blah = new int[5];
and then like
if(othervar == othervar)
{
set some values of blah
}
and then can i see if all the values of blah are set?

When you create the array using the new keyword, each array element is automatically initialised to the default value for the primitive. (Primitive types include bytes, chars, ints, longs, floats, etc, etc.) The defaut value for the integer type is 0, so all elements will automatically be initialised to 0. Thus, all the elements are already 'set'.

To summarise and avoid any further confusion...

If you declare a primitive variable (e.g. byte, char, int, float, etc.) as a class/instance variable (i.e. at the class level, not within a method), then the variable is automatically assigned its default value, assuming you don't assign a value yourself. For numeric primitives, this is always 0. For booleans, the default is false.

Array elements behave the same way, wherever/whenever (sorry for the Shakira link there) they are created using the new keyword.

Objects declared as class/instance members are automatically initialized to null.

If you declare a primitive variable within a method, the variable is local to whatever block the variable is declared in, and the variable is NOT initialised. This is why you have to initialize local variables before you use them. Similarly, objects declared with local scope are not initialized. To avoid compiler errors, it's often a good idea to initialize them to null at declaration time.