对于对象来说:"=="是比较两个对象的引用,看他们是不是引用相同的实例。
     "equals()"是比较两个对象的内容,看他们的内容是不是相等的。
对于基本数据类型来说:只有"==",用它来比较两边的数据是不是相等。

解决方案 »

  1.   

    equals()对于类型String来说当然是比较两个字符串是否每个字符都一致
    equals不过是一个成员方法,如果愿意可以继承String 且改写它
    比如比较头一个字符就算相等…
      

  2.   

    简单地说“==”是值比较。
    equals()是对象比较 
    举个例子吧:
    int a=2;
    int b=2;
    a==b返回的是true,但a.equals(b)是不允许的;
    Integer c = new Integer(2);
    Integer d = new Integer(2);
    c.equals(d) 返回值是true
    而c==d返回的是false(c和d此时成了对象)一般容易在String上犯错误.
    要注意的有两点:
    一.String 是一 个对象Object!
    二.java 中有String pool的概念,在String pool 中只有一个相同对象的实例.
    如String s1="aaa";
    String s2="aaa";
    在String pool中,只有一个aaa
    所以s1==s2是true
    s1.equals(s2)也是true
    明白了吧!
      

  3.   

    class如果不实现equals()方法,和==效果是一样的,很多class你可以实现自己的equals方法。比如String类,equals()方法已经被这样实现:public boolean equals(Object anObject) {
    if (this == anObject) {
        return true;
    }
    if (anObject instanceof String) {
        String anotherString = (String)anObject;
        int n = count;
        if (n == anotherString.count) {
    char v1[] = value;
    char v2[] = anotherString.value;
    int i = offset;
    int j = anotherString.offset;
    while (n-- != 0) {
        if (v1[i++] != v2[j++]) {
    return false;
        }
    }
    return true;
        }
    }
    return false;
        }
      

  4.   

    When you use == with a primitive -int, double, char, ... you are checking that
    the values are identical. But if you use == with an object, you are checking that the 2
    objects are stored at the same address. In other words the references pointing to the
    same object...
    Method equals () is different.
    It is the same as ==, if it isn't overriden by the object class.
    Many classes override the method equals (). In this case this method will check that
    content of the object is the same or not, not addresses.
      

  5.   

    在object的class里面,equals方法就是简单的==,大家平时用的String.equals()都是经过实装的,明白这个道理就够了。
      

  6.   

    ==就是比较两个引用是否指向同一个实例。
    equals()在Object中的定义和==是一致的,但是作为函数他是可以被重载的,比如
    在String和Boolean中,它就被重载为比较两个对象的值是否相等
      

  7.   

    “==”是一个逻辑运算符;
    “equals()”是Object类的一个成员函数。
      

  8.   

    "  一个是全等性,一个是同等性,即一个是判断是否指向同一对象,一个是判断所指向对象是否等价。" //nod ,:P 
      

  9.   

    例子:
    String s1="123";
    String s2="123";
    s1==s2   //返回为false
    s1.equals(s2)  //返回为真
      

  10.   

    是的吗,这位楼上的朋友?
    String s1="123";
    String s2="123";
    s1==s2   //返回为false----------------------是false吗???
    s1.equals(s2)  //返回为真 
      

  11.   

    基本数据类型用==可以 如int,double(小写的)
    类的对象用equals 如String,Integer
      

  12.   

    The == operators are straightforward when the operands are primitives. When  the operands are references, the operators test for referece quality. This means that the refereces are checked to see if they point to the same object.(This is distinct from object equality, under which two different objects are considered equal if their significant instance variables are equal.)