1

I use this...

IO.println( Arrays.deepToString( array ) );

to print my Array on the Screen. The result:

[[., ., ., ., ., ., .], [., ., ., ., ., ., .], [., ., ., ., ., ., .], [., ., .,
., ., ., .], [., ., ., ., ., ., .]]

My problem, I want it would looking like this:

[[., ., ., ., ., ., .], 
 [., ., ., ., ., ., .], 
 [., ., ., ., ., ., .], 
 [., ., ., ., ., ., .], 
 [., ., ., ., ., ., .]]

Can you help me to find a way to format this "print of an array"?

Thank you very much!

and sorry for my english...

2 Answers 2

2

You could use this:

IO.println(Arrays.deepToString(array).replace("], [", "],\n ["));

Thus replacing every ], [ by ],\n [ whereas \n adds a newline to the string.

Sign up to request clarification or add additional context in comments.

1 Comment

You'll want a space after the \n to match the OP's sample output.
0

add \n between the segments

System.out.println([[.,.,.], \n [[.,.,.], \n .......);

as you continue the pattern each \n starts a new line

Edit: result of that code would be: (also dont use the format just use your array and array number ie: System.out.println(array[1] /n array[2] /n array[3]

[[.,.,.],

[[.,.,.],

.........

2 Comments

Thanks for answering. To do this, was one of my first trys... The problem is that I dont know the "size of the array". Thats why I use the deepToString method. And I dont found a way to tell this method to use "/n" between the rows
array.length with no parenthesis will tell you the array length, the /n should be \n sorry

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.