Here’s a handy feature for those times when you want to clean up your code a little. When you want to condense two or more lines into one, you would normally use Home or End and then Delete or Backspace. But not all Java statements can be so easily combined, and joining lines manually can become a tedious time-waster. Thankfully, IntelliJ IDEA adds a little extra intelligence by providing the Smart Line Join editor command.
For example, when a String concatenation expression spans multiple lines, it can be a pain to delete the quotes and plus signs, but Smart Line Join will handle this with just one shortcut.
With the cursor on the first line, press Ctrl-Shift-J and the String literals on both lines are joined together, removing the redundant concatenation:
Likewise, when a declaration and initialization of the same variable are split onto two lines, they are quickly joined into one line.
Press Ctrl-Shift-J and the initialization is embedded into the declaration:
The Smart Line Join feature is also able to handle other not-so-simple joins, like joining several line-comments (//) joined into a single line-comment, etc.
Want IntelliJ IDEA T-Shirt?
Visit our Apparel Store!