我被檢查的字符串比較方法用於字符串compsrsion探索串類的decomplier,來到知道,基本上有四種方法關於字符串比較
equals()
equalsIgnoreCase()
compareTo()
compareToIgnore()
現在我想知道的區別我們使用他們的equals()和的compareTo()兩種方法,基本上請指教爲什麼string類一直保持這兩種方法..
String tv = "Bravia";
String television = "Bravia";
// String compare example using equals
if (tv.equals(television)) {
System.out.println("Both tv and television contains same letters and equal by equals method of String");
}
// String compare example in java using compareTo
if (tv.compareTo(television) == 0) {
System.out.println("Both tv and television are equal using compareTo method of String");
}
輸出: -
Both tv and television contains same letters and equal by equals method of String
Both tv and television are equal using compareTo method of String
你問返回true。我已經實現了它... – Ahmad 2013-02-17 06:56:41