Java boolean equals(Object anObject) 方法

Java String 类


equals() 方法用于将字符串与指定的对象比较。

语法

public boolean equals(Object anObject)

参数

  • anObject -- 与字符串进行比较的对象。

返回值

如果给定对象与字符串相等,则返回 true;否则返回 false。

实例

public class Test { 
     public static void main(String args[]) {
          String Str1 = new String("itzixishi");
          String Str2 = Str1; 
          String Str3 = new String("itzixishi");
          boolean retVal;

          retVal = Str1.equals( Str2 );
          System.out.println("返回值 = " + retVal );

          retVal = Str1.equals( Str3 );
          System.out.println("返回值 = " + retVal );
     }
}

以上程序执行结果为:

返回值 = true
返回值 = true

Java String 类

本教程仅供参考学习,如用于商业带来的问题,本站概不负责。
关注公众号
关注公众号

©2020 IT自习室京ICP备20010815号