Java String.equals 與 ==


String.equals()比較內容,而 == 檢查引用是否指向同一物件。

示例

請參見下面的示例 −

public class Tester {
   public static void main(String[] args) {
      String test = new String("a");
      String test1 = new String("a");
      System.out.println(test == test1);
      System.out.println(test.equals(test1));
   }
}

輸出

false
true

更新於:24-2-2020

211 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始學習
廣告
© . All rights reserved.