//This is the Comparator
public class Comparison implements Comparator
{
//This method takes two objects, compares them and returns the result
public int compare(Object o1, Object o2)
{
//Program logic
return -1;
}
}
//This object makes use of comparators to compare two strings
public class OtherClass
{
public OtherClass(Comparator c)
{
//Compare two strings using the given comparator. Different comparators may give different results.
if(c.compare(new String("test"), new String("test 2"))
//do something
}
}
//Sample main method making use of the above
public static void main(String[] args)
{
Comparator c = new Comparison();
OtherClass obj = new OtherClass(c);
}