Here you can find the source of getSortedLinkedHashMap(Map bitCounts, Comparator
public static LinkedHashMap getSortedLinkedHashMap(Map bitCounts, Comparator<Object> comparator)
//package com.java2s; //License from project: Open Source License import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; public class Main { public static LinkedHashMap getSortedLinkedHashMap(Map bitCounts, Comparator<Object> comparator) { List<Map.Entry> bitCountsList = new LinkedList(bitCounts.entrySet()); Collections.sort(bitCountsList, comparator); LinkedHashMap bitCountsSorted = new LinkedHashMap(); for (Map.Entry entry : bitCountsList) { bitCountsSorted.put(entry.getKey(), entry.getValue()); }/*from w w w .j av a 2 s . c om*/ return bitCountsSorted; } }