So with one key, it will turn code like this:
1
| System.out.println( "The year " + year + " is a leap year." ); |
Into this:
1
2
3
4
5
| StringBuilder message = new StringBuilder(); message.append( "The year " ); message.append(year); message.append( " is a leap year." ); System.out.println(message.toString()); |
First select the string part that you want to convert. The quickest way is to use the Select Enclosing Element shortcut (Alt+Shift+Up) to quickly select the parts of the string. Then press Ctrl+1 and select Use StringBuilder for string concatenation.
Just to show you how nice this feature is and how much time it can save, here’s a video that converts a 3 part string into 3 calls to a StringBuilder variable called message.As an added bonus, you can also convert the concatenation into a call to MessageFormat, but only if the concatenation contains a variable part. After you press Ctrl+1 just select Use MessageFormat for string concatenation. The example above should look something like this:
System.out.println(MessageFormat.format( "Playing {0} is fun." , soccer)); |
No comments:
Post a Comment