Using Smart Line Joins

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.

Joining string literals

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:

String literal after joining

Likewise, when a declaration and initialization of the same variable are split onto two lines, they are quickly joined into one line.

Joining declaration and initialization

Press Ctrl-Shift-J and the initialization is embedded into the declaration:

Initializtion and declaration joined

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.

This article was originally posted in JavaLobby Tips by Rob Harwood
Technorati tags: , , ,
This entry was posted in New Features and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>