What's the quickest way to combine two Object2IntOpenHashMap[String] in scala? Looking to combine these two maps:
val foo = new Object2IntOpenHashMap[String]
foo.put("foo", 1)
val bar = new Object2IntOpenHashMap[String]
bar.put("foo", 1)
bar.put("bar", 1)
And produce an output of {"foo" : 2, "bar" : 1}.
Below is the imperative way to combine the 2 Object2IntOpenHashMap values.
The above
println(foo)will print{bar=>1, foo=>2}.But if you want more functional way you should use more functional ibraries like cats or scalaz. I did this using cats -
You will get the same result as before. You can see the documentation here for semigroup here.