Here you can find the source of mergeMaps(Map
public static <K, V> void mergeMaps(Map<K, V> dest, Map<K, V> inserts)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany * Technical University Darmstadt, Germany * Chalmers University of Technology, Sweden * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// w ww .ja v a 2 s . co m * Technical University Darmstadt - initial API and implementation and/or initial documentation *******************************************************************************/ import java.util.Map; public class Main { public static <K, V> void mergeMaps(Map<K, V> dest, Map<K, V> inserts) { for (Map.Entry<K, V> entry : inserts.entrySet()) { K key = entry.getKey(); V value = entry.getValue(); if (!dest.containsKey(key) || (dest.containsKey(key) && dest.get(key) != value)) { dest.put(key, value); } } } }