String str1 = "a";

String str2 = "a";

str1 == str2   true;

 

String str1 = new String("a");

String str2 = new String("a");

 

str1 == str2  false;

str1.equal(str2)    true;

用new String 创建的字符串对象不能放入常量池中,它们有自己的地址空间。

相关文章:

  • 2022-02-07
  • 2022-12-23
猜你喜欢
  • 2021-11-05
  • 2021-07-02
  • 2021-08-06
  • 2021-11-07
  • 2022-02-05
  • 2021-12-10
相关资源
相似解决方案