Use the hash map here: org.apache.spark.util.collection.OpenHashMap

It is way faster than Java's, uses less memory, and the changeValue function allows you to use a single lookup to do lookup and update the value (so you can avoid the two hash lookups)