gpt4 book ai didi

java - New String 与 String s = "something",有什么区别?

转载 作者:行者123 更新时间:2023-12-01 07:27:11 25 4
gpt4 key购买 nike

考虑代码:

public class Strings {

public static void createStr()
{
String s1 = new String("one");
String s2 = "one";

System.out.println(s1);
System.out.println(s2);
}

public static void main(String args[])
{
createStr();
}

}

String s1 = new String("one"); 和有什么区别和String s2 = "one";

最佳答案

  String s1 = new String("one"); // will be created on the heap and not interned unless .intern() is called explicityly. 
String s2 = "one"; // will be created in the String pool and interned automatically by the compiler.

关于java - New String 与 String s = "something",有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22605225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com