zoukankan      html  css  js  c++  java
  • 08_==和equals()

    使用 == 和 equals() 比较字符串。

    String 中 == 比较引用地址是否相同,equals() 比较字符串的内容是否相同:

    String s1 = "Hello";              // String 直接创建
    String s2 = "Hello";              // String 直接创建
    String s3 = s1;                   // 相同引用
    String s4 = new String("Hello");  // String 对象创建
    String s5 = new String("Hello");  // String 对象创建
     
    s1 == s1;         // true, 相同引用
    s1 == s2;         // true, s1 和 s2 都在公共池中,引用相同
    s1 == s3;         // true, s3 与 s1 引用相同
    s1 == s4;         // false, 不同引用地址
    s4 == s5;         // false, 堆中不同引用地址
     
    s1.equals(s3);    // true, 相同内容
    s1.equals(s4);    // true, 相同内容
    s4.equals(s5);    // true, 相同内容
    

      

    https://www.runoob.com/java/java-string-equals.html

    https://blog.csdn.net/caoxuecheng001/article/details/88804286

  • 相关阅读:
    bzoj 1084: [SCOI2005]最大子矩阵
    Python之深浅拷贝
    2,版本控制git --分支
    1,版本控制git--仓库管理
    python-openpyxl操作excel
    ansible-3
    ansible-2
    ansible-1
    celery
    6,MongoDB 之 Array Object 的特殊操作
  • 原文地址:https://www.cnblogs.com/Thui/p/15785269.html
Copyright © 2011-2022 走看看