Java中的String类型

如下面的代码

 

public class StringTest 
{
	static final String s1 = "H";
	static final String s2 = "ello";
	static final String s3 = "Hello";
	
	static String ss1 = "H";
	static String ss2 = "ello";
	static String ss3 = "Hello";
	
	static final String s11;
	static final String s22;
	
	static
	{
		s11 = "H";
		s22 = "ello";
	}
	
	public static void main(String[] args)
	{
		//1
		String str1 = "H";
		String str2 = "ello";
		String str3 = "Hello";
		String str4 = str1 + str2;
		String str5 = "H" + "ello";
		
		System.out.println(str4 == str3);
		System.out.println(str5 == str3);
		
		//2
		String s4 = s1 + s2;
		
		System.out.println(s4 == s3);
		System.out.println(s4 == str3);
		
		//3
		String ss4 = ss1 + ss2;
		System.out.println(ss4 == s3);
		System.out.println(ss4 == ss3);
		System.out.println(ss4 == str3);
		
		//4
		String s33 = s11 + s22;
		System.out.println(s33 == s3);
		System.out.println(s33 == ss3);
		System.out.println(s33 == str3);
	}
}

 

 

输出为:

 

false
true
true
true
false
false
false
false
false
false

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值