"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.

"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

     

Advertisements

Share on Google+Share on Google+

"TreeSet" example in JRuby

Posted on: September 29, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: "TreeSet" example in JRuby  

Post your Comment


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

Ads

 

Ads