Definition Of Comparator Interface
You can found comparator interface in java.util.package and it contains 2 methods. Thus 2 of those methods are : .compare(obj1, obj2) and equals(Object element)
public int compare(object1, object2)
Java Comparator Example (non-generic style)
Thus for this example I’ve created 2 class of sorting elements in the base of age and name. Due to the sake of simplicity of this article i’ve only created 2 :
- Age Comparator
- Name Comparator
The programming language that I specialize in is Java, because I think Java programming language is more universal and of course because I like it regardless of any reason.