Tuesday, 17 September 2013

Is it possible to instantiate an array of variable lengths with indices of all -1 in JAVA?

Is it possible to instantiate an array of variable lengths with indices of
all -1 in JAVA?

Is it possible to create an integer array i with a variable length k,
where all indices are some specified value, say -1?
I know I could do something like:
int[] i = new int[k];
for (int a = 0; a < k; a++) {
i[a] = -1;
}
Are there any short-cuts that would not require the for-loop?

No comments:

Post a Comment