Skip to content

Instantly share code, notes, and snippets.

@woodie
Created July 6, 2010 08:21
Show Gist options
  • Save woodie/465160 to your computer and use it in GitHub Desktop.
Save woodie/465160 to your computer and use it in GitHub Desktop.
convert list to int[]
import stdlib.Array
import java.util.Arrays
class ArrayTest
def self.from_list
ints = Array.of_ints [3,6,2,9,5,7,4,8]
Arrays.sort(ints)
for i in ints
puts i
end
end
end
puts ArrayTest.from_list
# when you pass in lists of junk, bad things happen
# ints = Array.of_ints [3,"foo",2,9.0,"bar",7,4,8]
# java.lang.String cannot be cast to java.lang.Integer
# make sure this is compiled and on your $CLASSPATH
# http://github.com/takeru/dubious/blob/master/lib/stdlib/array.duby
$ duby array_test.duby
2
3
4
5
6
7
8
9
null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment