Here you can find the source of mergeMapList(List
public static <K, V> Map<K, V> mergeMapList(List<Map<K, V>> list)
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class Main { public static <K, V> Map<K, V> mergeMapList(List<Map<K, V>> list) { Map<K, V> ret = new HashMap<K, V>(); for (Map<K, V> listEntry : list) { if (listEntry == null) { continue; }// w w w . j ava2 s . c om for (Entry<K, V> mapEntry : listEntry.entrySet()) { K key = mapEntry.getKey(); V value = mapEntry.getValue(); V retValue = (V) add(ret.get(key), value); ret.put(key, retValue); } } return ret; } public static Object add(Object oldValue, Object newValue) { if (oldValue == null) { return newValue; } if (oldValue instanceof Long) { if (newValue == null) { return (Long) oldValue; } else { return (Long) oldValue + (Long) newValue; } } else if (oldValue instanceof Double) { if (newValue == null) { return (Double) oldValue; } else { return (Double) oldValue + (Double) newValue; } } else { return null; } } }