菜鸟学Java之Java与C++在字符串中使用+和==的区别
先看两段程序:
C++:
string str1="hello"; string str2="world"; string str3="helloworld"; string str4=(str1+str2).intern(); System.out.println(str3==str4);结果:true。
再看C++解释:
使用+连接字符串会创建一个新的字符串对象,使用==表示按照字典顺序比较字符串常量值,而不是比较是否引用同一对象。