123456 public void (){ String s0="helloworld"; String s1="helloworld"; System.out.println(s0==s1); } 123456 public void test4(){ String s0="helloworld"; String s1=new String("helloworld"); System.out.println( s0==s1 ); //false s0跟s1是不同的对象} “==”操作符的作用 用于基本数据类型的比较 判断引用是否指向堆内存的同一块地址。 12345 String s1 = new String("java");String s2 = new String("java");System.out.println(s1==s2); //falseSystem.out.println(s1.equals(s2)); //true 所以字符串比较尽量用equals 赞微海报分享
近期评论