Here you can find the source of sortMap(Map
public static <K, V> Map<K, V> sortMap(Map<K, V> targetMap, List<K> sortedList)
//package com.java2s; //License from project: Apache License import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class Main { public static <K, V> Map<K, V> sortMap(Map<K, V> targetMap, List<K> sortedList) { LinkedHashMap sortedMap = new LinkedHashMap(); Iterator var3 = sortedList.iterator(); while (var3.hasNext()) { Object k = var3.next(); if (targetMap.get(k) != null) { sortedMap.put(k, targetMap.get(k)); }/*from w w w . j ava 2 s . c o m*/ } return sortedMap; } }