Java Map Sort sort(Map map, Comparator> comparator)

Here you can find the source of sort(Map map, Comparator> comparator)

Description

sort

License

Open Source License

Declaration

public static <K, V> Map<K, V> sort(Map<K, V> map, Comparator<Map.Entry<K, V>> comparator) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static <K, V> Map<K, V> sort(Map<K, V> map, Comparator<Map.Entry<K, V>> comparator) {
        List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
        Collections.sort(list, comparator);

        Map<K, V> result = new LinkedHashMap<K, V>();
        for (Map.Entry<K, V> entry : list) {
            result.put(entry.getKey(), entry.getValue());
        }/*  w ww.j  av a  2  s.c o m*/
        return result;
    }
}

Related

  1. sort(Map map)
  2. sort(Map map)
  3. sort(Map src)
  4. sort(T map, Comparator> c)
  5. sortBy(Collection collection, final Map valuesMap)