Java比较两个字符串的=是假的吗?字符串部件是String[6]:["231", "CA-California", "Sacramento-155328", "aleee", "Customer Service Clerk", "Alegra Keith.doc.txt"]但当我比较parts[0]带着"231":"231" == parts[0]上面的结果是假的,我很困惑,有人能告诉我为什么吗?
3 回答
手掌心
TA贡献1942条经验 获得超3个赞
==
String
String
String.equals
"231".equals(parts[0]);
equals
==
equals
Object
慕村225694
TA贡献1880条经验 获得超4个赞
String s = "231";if(s == "231"){ System.out.println("true");}else{ System.out.println("false");}
String s = new String("231");if(s == "231"){ System.out.println("true");}else{ System.out.println("false");}
new
.equals()
添加回答
举报
0/150
提交
取消