Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Map; import java.util.Map.Entry; public class Main { public static <K> void merge(Map<K, Float> map1, Map<K, Float> map2) { if (map1 == null || isEmpty(map2)) { return; } for (Entry<K, Float> entry : map2.entrySet()) { K key = entry.getKey(); Float value = entry.getValue(); Float value2 = map1.get(key); if (value2 != null) { value += value2; } map1.put(key, value); } } public static <T> boolean isEmpty(Collection<T> col) { if (col == null || col.isEmpty()) { return true; } return false; } public static <K, V> boolean isEmpty(Map<K, V> map) { if (map == null || map.isEmpty()) { return true; } return false; } }