Accessing Java HashMap with Integer keys

Hi:

In the following program, the first ‘puts’ works but the second ‘puts’
returns a nil. If I am accessing a java HashMap that has
java.lang.Integer keys, is there a simpler way to get values out of the
map than the h.get used with the first ‘puts’?

Thanks,
David B.

require “java”
include_class “java.util.HashMap”

h = HashMap.new
h.put(java.lang.Integer.new(1), “aaa”)
h.put(java.lang.Integer.new(2), “bbb”)

puts h.get(java.lang.Integer.new(1)) # => “aaa” … OK
puts h.get(1) # => nil … no go

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs