IntelliJ IDEA makes it possible to concatenate two unselected or several selected lines into one, removing the extra spaces, and providing the proper syntax. This operation smartly analyzes the lines being joined and treats them accordingly. For example, you can join lines of code, lines of comments, field declaration and initialization.
In this section:
- Place the caret on the line, to which the other lines should be added.
- Sequentially press
You can select the lines and pressto obtain the same result.
- Select the lines with string literals that should be joined.
Joining a field or variable declaration and assignment:
Pressingproduces the following result, with the unwanted spaces and variable name in the second line removed:
Consider the following pair of statements:
Pressto join these lines into a correct single-line statement.