Converting a Ruby hash to a Java HashMap

Hi,

To convert a Ruby array to a Java array, I can use .to_java. How can I
convert a Ruby hash to a Java HashMap?

Best,
Martin


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Well, I don’t know if this is the best way, but you can do this:
irb(main):005:0> h = java.util.HashMap.new({:foo => ‘bar’})
=> #<Java::JavaUtil::HashMap:0x2c5a1e6b @java_object={foo=bar}>

Just create a new hashmap passing in the ruby hash as a parameter to the
constructor.

Joe

On Tue, Sep 16, 2008 at 9:23 PM, Martin C. Martin

Great; thanks! That’s what I do to convert a JRuby String to a Java
String when auto coersion won’t work. It seems a little wasteful (the
conversion is done before the call to new, so that’s redundant) but at
least it kind of documents what I’m doing.

Best,
Martin

Joseph A. wrote:

On Tue, Sep 16, 2008 at 9:23 PM, Martin C. Martin
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email