“==“与equals的在字符串比较中的区别

==”:进行的是数值比较,如果用于对象比较上比较的是两个内存的地址数值
equals : 类提供的一个比较方法,可以直接进行字符串内容的判断

例:

package day04;

public class stringEqual {
public static void main(String[] args) {
	String strA = "scp";
	String strB = new String("scp");
	System.out.print("==判断:");
	System.out.println( strA == strB);
	System.out.println("equal判断:"+strA.equals(strB));
}
}

输出:

==判断:false
equal判断:true

猜你喜欢

转载自blog.csdn.net/qq_41663470/article/details/112909103