boolean equals(String Str) 
          Compares this string to the specified object. 
 boolean equalsIgnoreCase(String anotherString) 
          Compares this String to another String, ignoring case considerations. 

解决方案 »

  1.   

    boolean   str1.equals(str2)
      

  2.   

    ==比较的是两个string对象本身的地址是不是相等
    要用str1.equals(str2)
      

  3.   

    原因如下:
    因为String是引用类型的,不是基本数据类型,所以它们的比较是使用地址和值(相当于C中的指针)来比较的,因为它们是不同的对象,有不同的地址,所以str1!=str2永远都是true。而str1==str2永远是false。如果你中想比较它们的数值是否相等就使用str1.equals(str2)。使用==或者!=是对象的比较,它们为真的条件是:不仅要求是同一对象,而值也要求相等。