Java List Sort sortListByMapKey(List> list)

Here you can find the source of sortListByMapKey(List> list)

Description

sort List By Map Key

License

Apache License

Declaration

public static void sortListByMapKey(List<Map<String, Object>> list) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

public class Main {

    public static void sortListByMapKey(List<Map<String, Object>> list) {
        Collections.sort(list, new Comparator<Map<String, Object>>() {
            @Override//from  w  w w  .  j a  v a2  s .  c o m
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                // TODO Auto-generated method stub
                String name = o1.get("key").toString();
                String _name = o2.get("key").toString();
                int n1 = name.length(), n2 = _name.length();
                for (int i1 = 0, i2 = 0; i1 < n1 && i2 < n2; i1++, i2++) {
                    char c1 = name.charAt(i1);
                    char c2 = _name.charAt(i2);
                    if (c1 != c2) {
                        c1 = Character.toUpperCase(c1);
                        c2 = Character.toUpperCase(c2);
                        if (c1 != c2) {
                            c1 = Character.toLowerCase(c1);
                            c2 = Character.toLowerCase(c2);
                            if (c1 != c2) {
                                if (n1 == n2) {
                                    return (c1 - c2);
                                }
                            }
                        }
                    }
                }
                return n1 - n2;
            }
        });
    }
}

Related

  1. sortList(java.util.List types)
  2. sortList(List list)
  3. sortList(List items)
  4. sortList(List list, boolean asc)
  5. sortListAlphabetically(List list)
  6. sortListEntry(List firstList, List secondList)
  7. sortListOfDoublesAndRemoveDuplicates(List items, double tolerance, double toleranceSmallNumbers)
  8. sortListStingArrayByFirstDes( List list)
  9. sortLocales(final List locales)