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
}
}
Java - "==" and "equals" are different method to String Class
最新推荐文章于 2024-07-14 22:18:32 发布