Home Tutorials Jruby ArrayList example in JRuby



ArrayList example in JRuby
Posted on: September 30, 2008 at 12:00 AM
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

     

Related Tags for ArrayList example in JRuby:
crubyarraylistiosedjrubyarraylisttutorialusingriathiselementcreateelementsaddtolearnstoresseeareilsectioncanliuseceinmntcaddjadesemallmehowtorwhichsessatisllrayeaandarcctutorseqssrithstaccessseqndono


More Tutorials from this section

Ask Questions?    Discuss: ArrayList example in JRuby  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.