用 Java 中的 equals() 方法比較字串


String 類的 equals() 方法將此字串與指定物件進行比較。僅當引數不為 null,並且是表示與此物件相同的字元序列的 String 物件時,結果才為 true。

示例

 線上演示

public class Test {
   public static void main(String args[]) {
      Integer x = 5;
      Integer y = 10;
      Integer z =5;
      Short a = 5;
      System.out.println(x.equals(y));
      System.out.println(x.equals(z));
      System.out.println(x.equals(a));
   }
}

輸出

false
true
false

更新於: 30-Jul-2019

111 次瀏覽

開啟你的 職業生涯

完成課程認證

開始
廣告
© . All rights reserved.