Difference between Initializing string with new and “ ”

前端 未结 8 1561
离开以前
离开以前 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:04

    As we know that String class is immutable so , String str="Hello String"; is the best way of using String class so we can avoid memory wastage.When string with the same value created.

提交回复
热议问题