java String比较,“==”和“equal”区别

	public static void main(String[] args){

	
	    String str1 = new String("str");
            String str2 = new String("str");
            System.out.println("==比较 :"+ str1 == str2);
            System.out.println("equal比较:"+ str1.equals(str2));
            String str3 = "str1";
            String str4 = "str1";
            System.out.println("==比较 :"+ str3 == str4);
            System.out.println("equal比较:"+ str3.equals(str4));
 
		
	}
                

 输出结果:

equal比较:true

false

equal比较:true

posted @ 2013-10-30 13:47  little white  阅读(1017)  评论(0编辑  收藏  举报