Java examples for Language Basics:String
Comparing Strings with equals and compareTo methods
public class Main { public static void main(String[] args) { String apple = new String("Apple") ; String orange = new String("Orange") ; //from w ww .ja va2 s . c om 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)); } }