java compareto

compareTo() String Example

java.lang.String class comes with many methods to check two strings contain same characters in the same sequence. To do this, String class comes with equals(), compareTo(), equalsIgnoreCase() and compareToIgnoreCase() methods. This tutorial is on compareTo() String. Now we discuss compareTo() String method. Following is the method signature as defined in…

Comparable Example Java

Before going through this program, it is advised to go through the interface Comparable tutorial. In the following Employee program, compareTo() method of Comparable interface is used to sort the employees by their ages. To use the compareTo() method, Employee class implements Comparable interface. Example code on Comparable Example