java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 3942
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use TreeSet E-mail
User Rating: / 221
PoorBest 

TreeSet stores objects in a sorted manner. TreeSet stores its elements in a tree and they are automatically arranged in a sorted order.

TreeSet is not synchronized. If more than one thread wants to access it at the same time then it must be synchronized externally.

import java.util.*;

public class DemoTreeSet {

  public static void main(String[] args) {

    TreeSet t1 = new TreeSet();
    t1.add("ggg");
    t1.add("aaa");
    t1.add("ddd");
    t1.add("bbb");
    t1.add("nnn");
    t1.add("lll");

    System.out.println("Contents of treeset");

    Iterator it1 =t1.iterator();

    while(it1.hasNext()){
      Object o1 = it1.next();
      System.out.println(o1);
    }
  }
}

Output:

Contents of treeset
aaa
bbb
ddd
ggg
lll
nnn

 Related Tips

 
< Prev   Next >
 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.