First things first, check out the API at http://java.sun.com/products/jdk/1.2...html#compareTo(java.lang.String)
The documentation explains it pretty well. Basically you do this:
Code:
String strABC = new String("ABC");
String strDEF = new String("DEF");
if ( strABC.compareTo(strDEF) == 0 )
{
System.out.println("ABC is the same as DEF");
}
else if ( strABC.compareTo(strDEF) < 0 )
{
System.out.println("ABC comes before DEF");
}
else {
System.out.println("ABC comes after DEF");
}
In this case, "ABC comes before DEF" will print because the compareTo() will return a value less than 0.
Bookmarks