Explanation of HashMap#hash(int) method

>>> is the logical right shift (no sign-extension) (JLS 15.19 Shift Operators), and ^ is the bitwise exclusive-or (JLS 15.22.1 Integer Bitwise Operators). As to why this is done, the documentation offers a hint: HashMap uses power-of-two length tables, and hashes keys by masking away the higher bits and taking only the lower bits of … Read more

How do I access nested HashMaps in Java?

You can do it like you assumed. But your HashMap has to be templated: Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>(); Otherwise you have to do a cast to Map after you retrieve the second map from the first. Map map = new HashMap(); ((Map)map.get( “keyname” )).get( “nestedkeyname” );

How do I create a HashMap with type erased keys?

It seems like I could create a Hasher (e.g. RandomState), use that to manually calculate hash values, then store the u64 result in a HashMap<u64, _> but that seems kind of overly complex. Unfortunately that’s overly simple – since a hash function discards some information, hash tables don’t just work on hashes, they also need … Read more