Java tutorial
//package com.java2s; import java.util.Iterator; import java.util.Map; public class Main { public static Map getMap(Map mapOld, Map newMap) { Iterator iter = mapOld.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object obj = entry.getValue(); if (obj instanceof Map) { getMap((Map) obj, newMap); } else { String key1 = (String) key; String value1 = (String) obj; if (!newMap.isEmpty()) { int nn = 0; Iterator iter1 = newMap.entrySet().iterator(); while (iter1.hasNext()) { Map.Entry entry1 = (Map.Entry) iter1.next(); String key2 = (String) entry1.getKey(); String[] arr1 = key2.split("\\|"); String e1 = arr1[0]; int n1 = Integer.parseInt(arr1[1]); if (key1.split("\\|")[0].equals(e1) && n1 >= nn) { nn = n1 + 1; } } newMap.put(key1.split("\\|")[0] + "|" + nn, value1); } else { newMap.put(key1, value1); } } } return newMap; } }