Here you can find the source of toHashMap(final Map
public final static <K, V> HashMap<K, V> toHashMap(final Map<K, V> map)
//package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { public final static <K, V> HashMap<K, V> toHashMap(final Map<K, V> map) { if (map instanceof HashMap) { // cast to it return (HashMap<K, V>) map; } else {/* ww w . j av a 2 s . c om*/ // create new return new HashMap<>(map); } } }