Search code examples
javaintellij-idea

IntelliJ IDEA always formats one-line for statement into multi-line


IntelliJ keeps formatting this:

for (int i = 0; i < 10; i++) {

}

into this:

for (int i = 0;
     i < 10;
     i++) {

}

I prefer the first style(one-line statement) than the second. I tried many methods but failed, please help me.


Solution

  • You can change this by going to your Preferences (Command-, on Mac) Go to

    Editor -> Code Style -> Java -> Wrapping and Braces.

    Find for() statement in the list. Next to for() statement, you may see always wrap, click this and change it to Do not wrap.