此方法将此字符串与指定对象进行比较。当且仅当参数不为null并且是一个String对象,表示与此对象相同的字符序列时,输出为true。
public boolean equals(Object anObject)
这是参数的详细信息-
anObject - 与此字符串进行比较的对象。
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 ); } }
这将产生以下输出-
Returned Value=true Returned Value=true
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)