提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
用equals和compareTo方法比较字符串
/*来自 n o w j a v a . c o m*/ public class Main { public static void main(String[] args) { String apple = new String("Apple") ; String orange = new String("Orange") ; System.out.println(apple.equals(orange)); System.out.println(apple.equals(apple)); System.out.println(apple == apple); System.out.println(apple == orange); System.out.println(apple.compareTo(apple)); System.out.println(apple.compareTo(orange)); }//时 代 J a v a 提供 }