码迷,mamicode.com
首页 > 其他好文 > 详细

Chapter 4 : Control Structures 1 : Selection

时间:2014-11-17 13:54:04      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   strong   div   on   


Although it need not be, the expression is usually an identifier. Whether it is an identifier
or an expression, the value of the identifier or the expression can only be of type int, byte, short,
or char

 

 

public class StringComapre {
    
    public static void main(String[] args) {    
    
    String    str1 = new String("Hello");
    String    str2 = "Hello";
    
    if (str1 == str2)
        System.out.println("str1 equal str2");
    else
        System.out.println("str1 != str2");
    
    ////////////////////////////////////////////////////////
    
    String    str3 = "Hello";
    String    str4 = new String("Hello");
    
    if (str3 == str4)
        System.out.println("str3 equal str4");
    else
        System.out.println("str3 != str4");
    
    ///////////////////////////////////////////////////////
    
    String    str5 = new String("Hello");
    String    str6 = new String("Hello");
    
    if (str5 == str6)
        System.out.println("str5 equal str6");
    else
        System.out.println("str5 != str6");
    
    }
}

  这段代码有疑问,为什么str1 和 str2不相等?

Chapter 4 : Control Structures 1 : Selection

标签:style   blog   io   color   ar   sp   strong   div   on   

原文地址:http://www.cnblogs.com/hare/p/4103321.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!