Java 字符串比较 compareTo方法


Java 字符串比较 compareTo方法

public class StringCompareEmp {
   public static void main(String args[]) {
      String str = "Hello World";
      String anotherString = "hello world";
      Object objStr = str;

      System.out.println( str.compareTo(anotherString) );
      System.out.println( str.compareToIgnoreCase(anotherString) );
      System.out.println( str.compareTo(objStr.toString()));
   }
}