String对象的相等
程序员文章站
2022-04-28 13:14:58
package objectNextPart; public class Final { Final(String a) { } public static void main(String[] args) { Final f1 = new Final("hello"); Final f2 = ne ......
package objectnextpart;
public class final {
final(string a) {
}
public static void main(string[] args) {
final f1 = new final("hello");
final f2 = new final("hello");
system.out.println(f1 == f2);// false
system.out.println(f1.equals(f2));// false
system.out.println(f1.hashcode());// 366712642
system.out.println(f2.hashcode());// 1829164700
string f3 = new string("world");
string f4 = new string("world");
system.out.println(f3 == f4);// false
system.out.println(f3.equals(f4));// true
system.out.println(f3.hashcode());// 113318802
system.out.println(f4.hashcode());// 113318802
}
}
上一篇: jdk1.5-1.10新特性
下一篇: 你们不是喜欢抓点点吗?