Is there a way to do the following at the same time?
static final int UN = 0; // uninitialized nodes
int[] arr;
// ... code ...
arr = new int[size];
for (int i = 0; i < 5; i++) {
arr[i] = UN;
}
Basically, I want to declare arr once I know what its size will be and initialize it to UN without having to loop. So something like this:
int[] arr = new int[size] = UN;
Is this possible?
Thanks.
No, not with the standard libraries. If you write your own functions, though, you can easily do so in a single statement (not instruction; those are different). Mine looks like
String[][] strings = Arrayu.fill(new String[x][y], "");Here’s a link. There’s some junk in there too, though; I just posted a copy of the current source directly without cleaning it up.