Here you can find the source of join(Map, ?> dst, Map, ?> src)
@SuppressWarnings("unchecked") public static void join(Map<?, ?> dst, Map<?, ?> src)
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.Map; import java.util.Set; public class Main { @SuppressWarnings("unchecked") public static void join(Map<?, ?> dst, Map<?, ?> src) { Map<Object, Object> dstMap = (Map<Object, Object>) dst; Map<Object, Object> srcMap = (Map<Object, Object>) src; Set<Object> srcKeySet = srcMap.keySet(); for (Object srcKey : srcKeySet) { Object srcValue = src.get(srcKey); Object dstValue = dst.get(srcKey); if (srcValue != null) { if (dstValue != null) { if (dstValue instanceof List) { List<Object> valueList = (List<Object>) dstValue; if (srcValue instanceof List) { valueList.addAll((List<Object>) srcValue); } else { valueList.add(srcValue); }/*from w ww . jav a 2s . co m*/ dstMap.put(srcKey, valueList); } else if (srcValue instanceof List) { List<Object> valueList = (List<Object>) srcValue; valueList.add(dstValue); dstMap.put(srcKey, valueList); } else { dstMap.put(srcKey, srcValue); } } else { dstMap.put(srcKey, srcValue); } } } } }