Java - "==" and "equals" are different method to String Class

来源:互联网 发布:无主之地2天邈汉化mac 编辑:程序博客网 时间:2024/06/06 11:43


public class StringDemo {
public static void main(String[] args) {
String str="hello";
String str1=new String("hello");
System.out.println(str==str1);
//== is for the address of storing
System.out.println(str.equals(str1));
//equals is for the arguments of the address
//实例化对象的操作分配了两个内存空间,内容都为hello
}
}

0 0