Home Tutorials Jruby "TreeSet" example in JRuby



"TreeSet" example in JRuby
Posted on: September 29, 2008 at 12:00 AM
In the previous sections of JRuby tutorials we have learned about how to use Java classes in JRuby program now here is one more example that uses Java class TreeSet.

"TreeSet" example in JRuby

     

In the previous sections of JRuby tutorials we have learned about how to use Java classes in JRuby program now here is one more example that uses Java class TreeSet. 

In this example we have first included java.util.TreeSet class and then we have created a new instance of TreeSet class. To add elements in this TreeSet object we have used add method.

Here is the example code TreeSetExample.rb as follows:

TreeSetExample.rb

require "java"
include_class "java.util.TreeSet"
   set = TreeSet.new
   set.add "Amit"
   set.add "Kumar"
   set.add "Vineet"
   set.each do |v|
   puts "values #{v}"
   end

Output:

On executing JRuby program following output will be generated:

C:\JRuby>jruby TreeSetExample.rb
values Amit
values Kumar
values Vineet

Download Source Code

     

Related Tags for "TreeSet" example in JRuby:
javacrubyclasstutorialstreeioclassesjrubyvitutorialriasetexampleprogramtolearnramexamsseearesectionlsuseinnoasmouttrjcleshowprotortreesxaxampseeatishamplpreeaartreesetvausestutorssrithavabhatpleplpronogro


More Tutorials from this section

Ask Questions?    Discuss: "TreeSet" 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.