forum

Home / DeveloperSection / Forums / Sorting ArrayList Based on Value of Long using java

Sorting ArrayList Based on Value of Long using java

Anonymous User230305-Oct-2013

I am attempting to sort an ArrayList based on the value of a long present within each object. After following various examples around the internet, I have come up with the following code but it is not sorting as desired (it seems to truncate parts of the object).

public static Comparator<Customer> compareSIN = 
         new Comparator<Customer>() {
            public int compare(Customer cust1, Customer other) {
               String sin1 = "" + cust1.sin;
               String sin2 = "" + other.sin;
               return sin1.compareTo(sin2);
            }
         };

Please advise me on what I am doing missing in the first snippet of code that is preventing me from sorting the objects properly.

Thanks!


Updated on 05-Oct-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By