Dean J.
Dean J.

Reputation: 35

Autofill multi dimensional String[][] array

I have a String array:

String[][] array = new String[7][6];

And I want to auto-fill everything with "[]", with one loop to basically set a default value. I tried to use Arrays.fill but it didn't work out well.

Upvotes: 1

Views: 60

Answers (2)

Man H
Man H

Reputation: 77

This will work for you if you want it in one loop.

String[][] myArray = new String[7][6];
int i, j;
for(i=0; i<7; i++)
{
j=i;
myArray[i] [j]= " ";
j++;
myArray[i] [j]= " ";
j++;
myArray[i] [j]= " ";
j++;
myArray[i] [j]= " ";
j++;
myArray[i] [j]= " ";
j++;
myArray[i] [j]= " ";
}

Upvotes: 0

user1089451
user1089451

Reputation:

Arrays.asList(array).forEach(a->Arrays.fill(a,"[]"));

Upvotes: 1

Related Questions