Java 中使用 == 運算子比較字串


您可以使用 == 運算子比較兩個字串。但它比較的是給定變數的引用,而不是值。

例項

即時演示

public class Sample {
   public static void main(String args[]){
      String str1 = "hello";
      String str2 = "hello";
      System.out.println(str1 == str2);
   }
}

輸出

true

更新時間: 26-Feb-2020

112 次瀏覽

開啟您的 事業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.