首页 > 其他 > 详细

Chapter 4 : Control Structures 1 : Selection

时间:2014-11-17 13:52:43      阅读:254      评论:0      收藏:0      [点我收藏+]


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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!