IntelliJ IDEA one-line function formatting

Intellij Idea

Intellij Idea Problem Overview


IntelliJ keeps formatting this:

public void addElement(Element elem) {
    this.elements.add(elem);
}

into this:

public void addElement(Element elem) { this.elements.add(elem); }

I prefer the multi-line formatting. How can I tell this to IntelliJ? I have unchecked the following boxes in Settings -> Editor -> Java -> Wrapping and Braces

  • Control statements in one line
  • Simple blocks in one line
  • Simple methods in one line

Didn't help.

Intellij Idea Solutions


Solution 1 - Intellij Idea

Look in Preferences (or Settings), Editor, General, Code Folding, Collapse by default, One-line methods

enter image description here

Solution 2 - Intellij Idea

below is the shortcut for Merge multiple lines into a line -

Ctrl + Shift + J

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAtte JuvonenView Question on Stackoverflow
Solution 1 - Intellij IdeaKirbyView Answer on Stackoverflow
Solution 2 - Intellij IdeaAjay KumarView Answer on Stackoverflow