Here you can find the source of merge(Map
public static <T1, T2> Map<T1, T2> merge(Map<T1, T2> mapPriorityLeast, Map<T1, T2> mapPriorityFirst)
//package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { public static <T1, T2> Map<T1, T2> merge(Map<T1, T2> mapPriorityLeast, Map<T1, T2> mapPriorityFirst) { Map<T1, T2> newMap = new HashMap<>(); for (Map.Entry<T1, T2> entry : mapPriorityLeast.entrySet()) { newMap.put(entry.getKey(), entry.getValue()); }/*w ww . j a v a 2 s. com*/ // override for (Map.Entry<T1, T2> entry : mapPriorityFirst.entrySet()) { newMap.put(entry.getKey(), entry.getValue()); } return newMap; } }