Here is a simple yet effective trick for all Eclipse users. In Java we do lot of String concatenation using plain old “” + “”. It is easy but not too effective. StringBuilder is always preferred if you have too many strings to concate.
In below screencast, I convert concatenated strings to StringBuilder using eclipse Ctrl + 1 option.
Move cursor on String “foo” and press Ctrl + 1. It opens a context menu. Select option Use “StringBuilder” for string concatenation
String foo = "This" + "is" + "Sparta";
System.out.println(foo);
Once done, the code will be converted to below:
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("This");
stringBuilder.append("is");
stringBuilder.append("Sparta");
String foo = stringBuilder.toString();
System.out.println(foo);
Enjoy
via ViralPatel.net http://feedproxy.google.com/~r/viralpatelnet/~3/31caPuoFL5s/
No comments:
Post a Comment
If you have any question please let me know