The difference between "==" and equals in string comparison

" == ": It is a numerical comparison, if it is used for object comparison to compare the address of two memory values
equals : a comparison method provided by the class, which can directly determine the content of the string

Example:

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));
}
}

Output:

==判断:false
equal判断:true

 

Guess you like

Origin blog.csdn.net/qq_41663470/article/details/112909103