Comparable example in java

Comparable interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class’s natural ordering, and the class’s compareTo method is referred to as its natural comparison method. Lists and arrays of objects that implement this interface can be sorted automatically by Collections.sort and Arrays.sort […]

Continue reading


Comparator example in java

As the name suggest, The Comparator is used for comparing objects in Java. Using this concepts; Java objects can be sorted according to a predefined order A comparator object is capable of comparing two different objects. The class is not comparing its instances, but some other class’s instances. This comparator class must implement the java.util.Comparator […]

Continue reading


Enumeration example in java

An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series. Methods in Enumeration boolean hasMoreElements() Tests if this enumeration contains more elements. Object nextElement() Returns the next element of this enumeration if this enumeration object has at […]

Continue reading