What is the difference between “text” and new String(“text”)?

后端 未结 12 1141
悲&欢浪女
悲&欢浪女 2020-11-21 04:42

What is the difference between these two following statements?

String s = \"text\";

String s = new String(\"text\");
12条回答
  •  醉梦人生
    2020-11-21 04:54

    Although it looks the same from a programmers point of view, it has big performance impact. You would want to use the first form almost always.

提交回复
热议问题