Reputation: 26437
I want to create a 10 dimensional array that's filled with zeros.
If I simply use int[] array = new int[10];
do I have a guarantee that all int's in the array are zeros?
Upvotes: 26
Views: 71056
Reputation: 10720
int always has initial value of 0. so
new int[10]
is enough.
for other values use Arrays
utility class.
int arrayDefaultedToTen[] = new int[100];
Arrays.fill(arrayDefaultedToTen, 10);
this method fills the array (first arg) with 10 (second arg).
Upvotes: 56
Reputation: 53526
Doing a new int[10]
will be plenty. Refer to the authority for the default values.
Upvotes: 2