Java Map Merge mergeMaps(Map dest, Map inserts)

Here you can find the source of mergeMaps(Map dest, Map inserts)

Description

merge Maps

License

Open Source License

Declaration

public static <K, V> void mergeMaps(Map<K, V> dest, Map<K, V> inserts) 

Method Source Code

//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);
            }
        }
    }
}

Related

  1. mergeMap(Map first, Map second)
  2. mergeMapIntoMap(Map> source, Map> destination)
  3. mergeMapList(List> list)
  4. mergeMaps(Map m1, Map m2)
  5. mergeMaps(Map mainMap, Map defaultMap, String[] keys, boolean enforceValues)
  6. mergeMaps(Map into, Map from, boolean override)
  7. mergeMaps(Map m1, Map m2)
  8. mergeMaps(Map map1, Map map2)
  9. mergeMaps(Map defaultMap, Map customMap)