JRuby and Java Iterators
Java Iterators in JRuby behave exactly as you’d expect them to… It’s always a pleasant surprise.
require 'java' # Iterator list = java.util.ArrayList.new list.add("one") list.add("two") list.add("three") list.each{ |item| puts item.upcase } # Enumeration jar = java.util.jar.JarFile.new("jruby.jar") jar.entries.each{ |entry| puts entry.to_s }
C:\>jruby -v jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1. 5.0_15) [x86-java]