Java Map Sort sortMapByKey(Map data)

Here you can find the source of sortMapByKey(Map data)

Description

sort Map By Key

License

Open Source License

Declaration

public static <K extends Comparable, V> Map<K, V> sortMapByKey(Map<K, V> data) 

Method Source Code


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

import java.util.*;

public class Main {
    public static <K extends Comparable, V> Map<K, V> sortMapByKey(Map<K, V> data) {
        Map<K, V> data_ = new LinkedHashMap<>();
        List<K> list = new LinkedList<>(data.keySet());
        Collections.sort(list);//from  www. j a v  a 2s . c o  m
        for (K k : list) {
            data_.put(k, data.get(k));
        }
        return data_;
    }
}

Related

  1. sortMap(LinkedHashMap map, Comparator> c)
  2. sortMap(Map oldMap)
  3. sortMap(Map oldMap, final boolean asc)
  4. sortMap(Map map, int k)
  5. sortMap(Map map, Comparator> compator)
  6. sortMapByKey(Map map)
  7. sortMapByValue(Map input, final boolean desc)
  8. sortMapByValue(Map map, Comparator comparator)
  9. sortMapByValue(Map map, Comparator> valueComparator)