A DESCRIPTION OF THE PROBLEM :
The following are equivalent and should be compiled to the same byte code. I see this often in projects, developers use the String concatenation operator "+" inside the body of a StringBuilder/StringBuffer append method. When this is the case, the operator should be converted into an 'append' call on the parent StringBuilder/StringBuffer instead of creating a new StringBuilder/StringBuffer for the intermediate results.
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
sb.append(args[0] + ' ' + args[1]);
System.out.println(sb.toString());
}
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
sb.append(args[0]);
sb.append(' ');
sb.append(args[1]);
System.out.println(sb.toString());
}
The following are equivalent and should be compiled to the same byte code. I see this often in projects, developers use the String concatenation operator "+" inside the body of a StringBuilder/StringBuffer append method. When this is the case, the operator should be converted into an 'append' call on the parent StringBuilder/StringBuffer instead of creating a new StringBuilder/StringBuffer for the intermediate results.
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
sb.append(args[0] + ' ' + args[1]);
System.out.println(sb.toString());
}
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
sb.append(args[0]);
sb.append(' ');
sb.append(args[1]);
System.out.println(sb.toString());
}