字串比較 by equals() 方法,Java 中的方法
String 類中的 equals() 方法比較此字串與指定的物件。結果僅在引數非空並且是表示與本物件相同字元序列的 String 物件時為真。
示例
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
廣告