Java equals() 方法
equals() 方法用于将字符串与指定的对象比较。
语法
public boolean equals(Object anObject)
参数
anObject — 与字符串进行比较的对象。
返回值
- 如果给定对象与字符串相等,则返回 true;否则返回 false。
实例
public class Test {
public static void main(String args[]) {
String Str1 = new String("sunny");
String Str2 = Str1;
String Str3 = new String("sunny");
boolean retVal;
retVal = Str1.equals( Str2 );
System.out.println("返回值 = " + retVal );
retVal = Str1.equals( Str3 );
System.out.println("返回值 = " + retVal );
}
}
以上程序执行结果为:
返回值 = true
返回值 = true
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/97678.html