Which one is correct and why:
String dynamic = new String();
dynamic = \" where id=\'\" + unitId + \"\'\";
Or
String dynamic = \" where id=\'\" + unitId + \"
I guess the below will be good
String str; // Just declares the variable and the default will be null. This can be done in global scope or outer scope
str = "where id" + unitID + "'"; // Initializing string with value when needed. This will be done in the inner scope.
If declaration and initialization done in a line where the initialization contains dynamic text (unitID in your case) you can't do it globally. If Scope of the variable is not an issue then u may go ahead. Cheers!!