1

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.

2
  • Anything wrong with using two nested loops? Commented Feb 15, 2016 at 0:57
  • I dont know how to set the condition for the max. lenght of the loop in a multidimensional array and then actually set the value to "[ ]". Commented Feb 15, 2016 at 1:08

2 Answers 2

1
Arrays.asList(array).forEach(a->Arrays.fill(a,"[]"));
Sign up to request clarification or add additional context in comments.

2 Comments

That one looks pretty good, thanks. Could you maybe explain what that forEach exactly do?
0

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]= " ";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.