Difference between Initializing string with new and “ ”

前端 未结 8 1493
离开以前
离开以前 2021-01-27 08:21

Which one is correct and why:

String dynamic = new String();
dynamic = \" where id=\'\" + unitId + \"\'\";

Or

String dynamic = \" where id=\'\" + unitId + \"         


        
8条回答
  •  爱一瞬间的悲伤
    2021-01-27 09:09

    You can use like this.

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("where id='");
    stringBuilder.append(unitId);
    stringBuilder.append("'");
    
    String dynamic = stringBuilder.toString();
    

提交回复
热议问题