`

Java中的String类型

    博客分类:
  • Java
阅读更多

如下面的代码

 

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

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics