目录

boolean equals(Object anObject)

描述 (Description)

此方法将此字符串与指定的对象进行比较。 当且仅当参数不为null并且是表示与此对象相同的字符序列的String对象时,结果才为真。

语法 (Syntax)

以下是此方法的语法 -

public boolean equals(Object anObject)

参数 (Parameters)

这是参数的细节 -

  • anObject - 要比较此String的对象。

回报价值

  • 如果String相等,则此方法返回true; 否则是假的。

例子 (Example)

public class Test {
   public static void main(String args[]) {
      String Str1 = new String("This is really not immutable!!");
      String Str2 = Str1;
      String Str3 = new String("This is really not immutable!!");
      boolean retVal;
      retVal = Str1.equals( Str2 );
      System.out.println("Returned Value = " + retVal );
      retVal = Str1.equals( Str3 );
      System.out.println("Returned Value = " + retVal );
   }
}

这将产生以下结果 -

输出 (Output)

Returned Value = true
Returned Value = true
↑回到顶部↑
WIKI教程 @2018