Eclipse Formatting - Initializing a Multidimensional Array

I can't figure out how to get Eclipse to format multidimensional arrays the way I want ...

int firstarray[][] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, }; 

This is what I would like, but despite changing the wrapping of lines, position of shapes and new lines for the initializers of the array, I cannot make it look like this. The closest I could get is where none of them back down, and it really bothers me. :(

+4
source share
2 answers

I couldn't get exactly what you wanted, but I have something like this, hope this helps.

 int firstarray[][] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }; 

First go to window → settings, and under java → formatter you can edit the active profile.

Under the parentheses tab for the array initializer, set it to the "next line"

In the new lines tab for array initializers, check both "insert a new line after opening the array initializer bracket" and "insert a new line before closing the array initializer bracket"

Finally, on the line wrapper tab in expressions, click on the array initializers and set it to "wrap all elements, each element in a new line" and the indentation policy set to "indent by one"

Now just source → format to get the result, and you're done.

+2
source

Unfortunately, I could not find a great solution ... What can you do:

 { { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, // { { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, 1 } }, // { { 0, -1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } }, // { { 0, -1 }, { 0, 0 }, { 0, 1 }, { 0, 2 } } }; 

(just comment out lines between all subarrays)

0
source

Source: https://habr.com/ru/post/1487723/


All Articles