我被检查的字符串比较方法用于字符串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