Java equals() 方法
Java 教程
· 2019-02-08 20:57:02
equals() 方法用于将字符串与指定的对象比较。
语法
public boolean equals(Object anObject)
参数
anObject -- 与字符串进行比较的对象。
返回值
如果给定对象与字符串相等,则返回 true;否则返回 false。
实例
public class Test {
public static void main(String args[]) {
String Str1 = new String("codercto");
String Str2 = Str1;
String Str3 = new String("codercto");
boolean retVal;
retVal = Str1.equals( Str2 );
System.out.println("返回值 = " + retVal );
retVal = Str1.equals( Str3 );
System.out.println("返回值 = " + retVal );
}
}
以上程序执行结果为:
返回值 = true 返回值 = true
点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html
Programming Collective Intelligence
Toby Segaran / O'Reilly Media / 2007-8-26 / USD 39.99
Want to tap the power behind search rankings, product recommendations, social bookmarking, and online matchmaking? This fascinating book demonstrates how you can build Web 2.0 applications to mine the......一起来看看 《Programming Collective Intelligence》 这本书的介绍吧!