zoukankan      html  css  js  c++  java
  • Chapter 4 : Control Structures 1 : Selection


    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不相等?

  • 相关阅读:
    数据库子查询
    数据库简介
    MySql数据类型
    Jquery与js简单对比
    JS-对象
    JS-DOM
    JS-数组
    JS-函数
    JS-json
    JS-类型相关
  • 原文地址:https://www.cnblogs.com/hare/p/4103321.html
Copyright © 2011-2022 走看看