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



Home Tutorials Jruby "TreeSet" example in JRuby

Related Tutorials


 
 

Share on Google+Share on Google+

"TreeSet" example in JRuby

Advertisement
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

     

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 29, 2008

Related Tutorials

Discuss: "TreeSet" example in JRuby  

Post your Comment


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