I came across two pieces of code that created a request for further execution:
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("SELECT * FROM EMPLOYEE ");
stringBuilder.append("WHERE SALARY > ? ");
stringBuilder.append("GROUP BY DEPT");
and
String string = "SELECT * FROM EMPLOYEE " +
"WHERE SALARY > ? " +
"GROUP BY DEPT";
According to my analysis, both fragments create 4 objects. The first fragment creates a StringBuilder object and 3 string objects, and the second fragment creates 4 String objects. Is my analysis correct?
How effective is a snippet than fragment 2?
source
share