Java equals() 方法

返回到:Java 介绍String类

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

语法

public boolean equals(Object anObject)

参数

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

返回值

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

实例

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

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

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

以上程序执行结果为:

返回值 = true
返回值 = true

返回到:Java 介绍String类

作者:terry,如若转载,请注明出处:https://www.web176.com/java_api/19534.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年5月4日
下一篇 2023年5月5日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注