Which one is correct and why:
String dynamic = new String(); dynamic = \" where id=\'\" + unitId + \"\'\"; Or String dynamic = \" where id=\'\" + unitId + \"
Short answer:
String str = new String();
creates a new String object on the heap. When you do afterwards:
str = "Hello, String Pool";
You simply overwrite the reference to the first object with another reference. Thus, the first object is lost. Keep this in mind: Strings are immutable.