Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class Main { public static <G> List<G> combineWithOrder(LinkedHashMap<String, Integer> keyIdMap, Map<String, G> keyValueCacheMap, Map<Integer, G> idValueArticles) { List<G> ret = new ArrayList<G>(); for (Entry<String, Integer> keyIdMapEntry : keyIdMap.entrySet()) { String key = keyIdMapEntry.getKey(); Integer id = keyIdMapEntry.getValue(); G g = keyValueCacheMap.get(key); if (g == null) { g = idValueArticles.get(id); } if (g != null) { ret.add(g); } } return ret; } }