==对于基本数据类型来说是值的比较,对于引用类型来说是比较的是引用;而equals默认情况下是引用比较,只是许多类重写了equals方法,比如String、Integer等把它变成了值的比较,所以一般情况下equals比较的是值是否相同
实列一
package com.kaoshi; class Dog { public String name; public Dog(String name){ this.name =name; } } public class Demo1 { public static void main(String[] args){ Dog dog1 = new Dog("xiaohuang"); Dog dog2 = new Dog("xiaohuang"); String s1 = dog1.toString(); String s2 = dog2.toString(); String s3 = "xiaohuang"; String s4 = "xiaohuang"; System.out.println(dog1); System.out.println(dog2); System.out.println(s1); System.out.println(s2); System.out.println(dog1.equals(dog2));//equals默认情况下比较的是引用 System.out.println(s1.equals(s2)); System.out.println(s3.equals(s4));//这里的上s3,s4其实指向的是同一个引用 System.out.pri