What is the difference between strings allocated using new operator & without new operator in java J2ME?

后端 未结 5 1300
不知归路
不知归路 2020-12-03 23:39

what is the Difference between

String str=new String(\"Thamilan\");

and

String str=\"Thamilan\";

in java

5条回答
  •  长情又很酷
    2020-12-03 23:47

    In first case new object will be created always, in second case object from a string pool can be reused. Read more about String pool here: What is String pool?

提交回复
热议问题