Here you can find the source of sortMapByKey(Map
public static <K extends Comparable, V> Map<K, V> sortMapByKey(Map<K, V> data)
//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_; } }