First step: New sort temporary key in map
Initialize Map collection list<map<string, string>> columns = new arraylist<map<string, string>> (); map<string, string> c1 = new hashmap<string,string> (); C1.put ("Sort", "8"); C1.put ("title", " Www.chuweibiao.com "); Columns.Add (C1); map<string, string> c2 = new hashmap<string,string> (); C2.put ("Sort", "5"); C2.put ("title", " Www.chuweibiao.com "); Columns.Add (C2); Map<string, string> c3 = new hashmap<string,string> (); C3.put ("Sort", "all"); C3.put ("title", " Www.chuweibiao.com "); Columns.Add (C3);
Step Two: Sort the
/** * Map Type element Collection Sort * @param columns * Map type element collection */private void Listsortingformaptypeelement (list<map<string, object& gt;> columns) {collections.sort (columns, New comparator<map<string, object>> () {public int compare (MAP <string, Object> last, map<string, object> next) {Object lastsort = Last.get ("sort"); object nextsort = next.ge T ("sort"), if (Lastsort = = NULL | | nextsort = = NULL) {return 0;} else {return Integer.parseint (string.valueof (lastsort)) &G T Integer.parseint (string.valueof (nextsort))? 1:0;}});}
Step three: Remove temporary keys
/** * Remove sort temporary key * @param columns * MAP type element collection */private void Removesortkey (list<map<string, object>> columns) {fo R (map<string, object> column:columns) {column.remove ("sort");}}
who has a better way to make brick advice, O (∩_∩) o Thank you ~
Java Implementation Map Collection sorting function