From: Colin Bartlett Date: 2009-10-15T07:11:00+09:00 Subject: Re: how to solve a special JRuby and Java syntax conflict? Axel I hope this won't be taken the wrong way: I'm rather glad you had the problem and posted your question, because it prompted me to actually try out what I'd intended to do, and even more because Carl Leiby-2 gave a very elegant way of converting a whole array which I probably would not have found myself, and which will save me writing quite a few lines of code using the way I originally posted. So, to summarise for my benefit: in JRuby you can create a two dimension Ruby Array of doubles, and then convert it in one go to a JRuby Java Array as follows: rarr = [ [0.0, 0.1], [1.0, 1.1, 1.2, 1.3], [2.0], [3.0, 3.1, 3.2] ] jarr = rarr.to_java Java::double[] Note that it works even with different sizes of "sub-arrays". (But it won't work if - for example - you replace the [2.0] by 2.0.) For access to individual elements of the JRuby Java Array you can do: puts jarr[2][0] # getter jarr[2][0] = 2.0002 # setter puts jarr[2][0] # getter and - obviously - can write JRuby methods which process multiple elements by wrapping the access to individual elements. So, if, for some reason, the "to_java Java::double[]" way doesn't work, we can call a user-written Java method to create a Java Array with the appropriate dimensions and with values 0.0, and then populate it from JRuby by accessing the individual elements, or by passing individual values and their "indexes" to a user-written Java method which then sets the appropriate element in the Java Array. (I'm happier when I have more than one way to do things, as a "back-up".) So thanks for the original post, and for posting in the JRuby forums! Colin