Here you can find the source of replaceKey(final Map
public static <TKey, TValue> void replaceKey(final Map<TKey, TValue> map, final TKey oldkey, final TKey newkey) throws IllegalArgumentException
//package com.java2s; //License from project: Open Source License import java.util.Map; public class Main { public static <TKey, TValue> void replaceKey(final Map<TKey, TValue> map, final TKey oldkey, final TKey newkey) throws IllegalArgumentException { if (map != null && map.containsKey(oldkey)) { map.put(newkey, map.get(oldkey)); } else {/*from w w w.j a v a 2s .co m*/ throw new IllegalArgumentException("Map must be effective and contain the old key."); } } }