# Accessing Java HashMap with Integer keys

**URL:** <https://www.ruby-forum.com/t/accessing-java-hashmap-with-integer-keys/117135>\
**Category:** JRuby\
**Created:** [October 13, 2007, 5:48pm UTC](https://www.ruby-forum.com/t/accessing-java-hashmap-with-integer-keys/117135 "2007-10-13T17:48:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [October 13, 2007, 5:48pm UTC](https://www.ruby-forum.com/t/accessing-java-hashmap-with-integer-keys/117135/1 "2007-10-13T17:48:13Z")

</div>

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
