The difference between a reference data type of basic data types

Disclaimer: This article is copyrighted final HrainOne all, welcome to reprint, please declare final copyright https://blog.csdn.net/gaoxin_gx/article/details/90691863

Reference data types: comparing the reference data address is the same type of
basic data types: comparing the value of the basic data type is the same

Take, for example:

public class Main{
	public static void main(String[] args) {
		//引用数据类型
		String s1 = new String("hello");
		//基本数据类型
		String s2 = "hello";
		//基本数据类型
		String s3 = "hello";
		System.out.println("s1="+s1);	//s1=hello
		System.out.println("s2="+s2);	//s2=hello
		System.out.println("s1 = s2?"+(s1==s2));	//s1 = s2?false
		System.out.println("s1 = s2?"+(s3==s2));	//s1 = s2?true
	}
}

Guess you like

Origin blog.csdn.net/gaoxin_gx/article/details/90691863