someObject .compareTo ( anotherObject ) returns a negative number if someObject comes before another object.
Here is an example that compares String objects:
if ("apple".compareTo("zebra") < 0) { System.out.println("I will be printed"); } else { System.out.println("I will NOT be printed"); }
source share