I have a Java lib that I am pulling some data out of.
It out puts a 3D array. However I can not do anything with it.
[[D[]@5615a6e0
is the response I get. I have tried mapping it:
{ |arr| arr.map { |arr| arr.to_a } }
but i get nothing out, What is the best way to parse this java array for ruby use?
Should not be a problem. Just use to_a
Java Code:
package com.test.sof;
public class MyTest {
public static int[] ReturnTestArray() {
int[] anArray = new int[3];
anArray[0] = 1;
anArray[1] = 2;
anArray[2] = 3;
return anArray;
}
}
JRuby Code:
require 'java'
java_import com.test.sof.MyTest
java_array = MyTest.ReturnTestArray
p java_array
#=> int[1, 2, 3]@484c6b
ruby_array = Array.new
p ruby_array
#=> []
ruby_array = java_array.to_a
p ruby_array.size
#=> 3
p ruby_array.join(', ')
#=> "1, 2, 3"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With