Sunday 15 February 2015

java - Further Sort an already sorted list -


I have a list of maps which I have already sorted in a way but Now I want to sort the list forward

Basic Type

  Collections.sort (list, new comparison & lt; map & lt; string, object & gt; & Gt; () {@Override compare public int (map & lieutent; string, object & gt; m1, map & lt; string, object & gt; m2) {return m1.get ("type"). ToString (). Compare Switch to (m2.get ( "type"). ToString ()); // type 1 or 0}});   

Now I order what I want to do, but I want to sort that list forward with the previous names. Do I have to divide it into 2 lists, a list of type 0 and other type with 1 then add the list together?

Basically, I want to repeat a SQL type, where I'll type in type ASC, last name ASC and sort me a sort of sort sorted sort by last name Would like to do

You can:

  int compareType = m1 Get ("type") ToString () compareTo (m2.get ("type") toString ().); If (compareType! = 0) {return compare type; } Return m1.get ("name"). ToString () Compare (m2.get ("name"). ToString ());   

If you are sorting on several keys, then it will be cleaner:

 for  (string key: new string [] {"type", "Name"}) {Int compare = m1.get (key) .toString (). Compare (m2.get (key) .toString ()); If (comparison! = 0) {compare comparison; }} Return 0;    

No comments:

Post a Comment