java之String变量和“==”操作符(2)

如下面代码:

public class StringTest2 
{
	String s1 = "H";
	String s2 = "ello";
	String s3 = s1 + s2;
	String s4 = "H" + "ello";
	
	static String ss1 = "H";
	static String ss2 = "ello";
	static String ss3 = ss1 + ss2;
	static String ss4 = "H" + "ello";
	
	final String fs1 = "H";
	final String fs2 = "ello";
	final String fs3 = fs1 + fs2;
	final String fs4 = "H" + "ello";
	
	static final String sfs1 = "H";
	static final String sfs2 = "ello";
	static final String sfs3 = sfs1 + sfs2;
	static final String sfs4 = "H" + "ello";
	
	public static void main(String[] args)
	{
		StringTest2 st = new StringTest2();
		st.test1();
	}
	
	public void test1()
	{
		String str1 = "H";
		String str2 = "ello";
		String str3 = "Hello";
		String str4 = str1 + str2;
		String str5 = "H" + "ello";
		
		//1
		System.out.println(str3 == str4);
		System.out.println(str3 == str5);
		
		//2
		System.out.println();
		System.out.println(str3 == s3);
		System.out.println(str3 == s4);
		
		//3
		System.out.println();
		System.out.println(str3 == ss3);
		System.out.println(str3 == ss4);
		
		//4
		System.out.println();
		System.out.println(str3 == fs3);
		System.out.println(str3 == fs4);
		
		//5
		System.out.println();
		System.out.println(str3 == sfs3);
		System.out.println(str3 == sfs4);
	}
}

 

 

输出如下:

false
true

false
true

false
true

true
true

true
true

  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值