View RSS Feed

My Java Tips

  1. Difference Between Comparable And Comparator Interface

    by , 11-08-2011 at 07:29 PM (My Java Tips)
    Programmers are usually confused between "Comparable" and "Comparator" interface. Comparable interface has "compareTo" method which is normally used for natural ordering but Comparator interface has "compare" method which takes two arguments. It can be used where you want to sort objects based of more then one parameter. Following example will make it more clear.




    Java Code:
    package test;/*
     ** Use the Collections.sort to
    ...