Java tutorial
//package com.java2s; import java.util.Map; import java.util.Set; public class Main { /** * <p>Return subMap from target Map where the key start with appointing keyPrefix, subMap's remove keyPrefix</p> * <p>subMap([key1:value1,key21:value21,key22:value22], new HashMap(), key2) return [1:value21,2:value22]</p> * @param sourceMap * @param targetMap * @param keyPrefix * @return */ public static <E extends Object> Map<String, E> subMap(Map<String, E> sourceMap, Map<String, E> targetMap, String keyPrefix) { Set<Map.Entry<String, E>> entrys = sourceMap.entrySet(); for (Map.Entry<String, E> entry : entrys) { String key = entry.getKey(); if (key != null && key.startsWith(keyPrefix)) { targetMap.put(key.replace(keyPrefix, ""), entry.getValue()); } } return targetMap; } }