A Java Program to compare Strings by compring successive corresponding characters, starting with the first character in each String.
publicclass JAVA_048 { publicstaticvoid main(String[] args) { String String1="A"; String String2="To"; String String3="Z"; System.out.println("String1 : " + String1); System.out.println("String2 : " + String2); System.out.println("String3 : " + String3); if(String1.compareTo(String3)<0) System.out.println("String1 is less than String3"); else { if(String1.compareTo(String3)>0) System.out.println("String1 is greater than String3"); else System.out.println("String1 is equal to String3"); } if(String2.compareTo(String1)<0) System.out.println("String1 is less than String1"); else { if(String2.compareTo(String1)>0) System.out.println("String2 is greater than String1"); else System.out.println("String2 is equal to String1"); } } }