Here you can find the source of replaceKey(Map
public static <K, V> void replaceKey(Map<K, V> map, K oldKey, K newKey)
//package com.java2s; //License from project: Apache License import java.util.Map; public class Main { /**/*from ww w . j av a 2 s .com*/ * Remove the entry with 'oldKey' and put it (if exists) using 'newKey' unless if an entry already exist for 'newKey'. */ public static <K, V> void replaceKey(Map<K, V> map, K oldKey, K newKey) { if (map == null || map.isEmpty()) { return; } if (map.containsKey(newKey)) { return; } V o = map.remove(oldKey); if (o != null) { map.put(newKey, o); } } }