Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Tutorials Jruby ArrayList example in JRuby

Related Tutorials


 
 

Share on Google+Share on Google+

ArrayList example in JRuby

Advertisement
In this section of JRuby tutorial you will learn how to create and add elements in ArrayList using the JRuby.

ArrayList example in JRuby

     

In this section of JRuby tutorial you will learn how to create and add elements in ArrayList using the JRuby. ArrayList is used to store elements in the list which can be accessed sequentially.

In this example of ArrayList we have to include the ArrayList class as we import class file in simple java program. After including ArrayList we have created a new instance of ArrayList so that we can call add method of this class to add elements in it.

 

 

ArrayList.rb

require "java"
include_class "java.util.ArrayList"
  arrlist = ArrayList.new
  arrlist.add "Amit"
  arrlist.add "Kumar"
  arrlist.add "Vineet"
puts "#{arrlist}"

First line in ArrayList.rb file require "java" means that we are making our program enabled to use java classes and method. "puts" method prints array list on the console.

Output: 


C:\JRuby>jruby ArrayList.rb
[Amit, Kumar, Vineet]

C:\JRuby>

Download Source Code

     

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 30, 2008

Related Tutorials

Discuss: ArrayList example in JRuby  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com