TreeSet implementation

TreeSet implementation using Iterator

We already know implementation of ArrayList using Iterator Class in our ArrayList blogs. Here we will work on TreeSet implementation.

Now, we will see how to fetch data from TreeSet using iterator() method.

 

TreeSet collection type gives ascending order of this data.

 

Let’s see simple example on TreeSet implementation.

 

import java.util.*;

class collection9

{

                public static void main(String args[])

                {

                                TreeSet<String> set1 = new TreeSet<String>();

                                set1.add(“Vikash Gohel”);

                                set1.add(“Jigar Patel”);

                                set1.add(“Geet Vyas”);

                                set1.add(“Piyush Darji”);

                                set1.add(“Kiran Vagle”);

                                System.out.println(set1);

 

                                Iterator itr = set1.iterator();

                                while(itr.hasNext())

                                {

                                                System.out.println(String.valueOf(itr.next()).toUpperCase());

                                }

                }

}

Output

[Geet Vyas, Jigar Patel, Kiran Vagle, Piyush Darji, Vikash Gohel]

GEET VYAS

JIGAR PATEL

 KIRAN VAGLE

PIYUSH DARJI

VIKASH GOHEL

 

Visit this program in YouTube Channel


For more videos on Java visit our YouTube Channel


Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

380total visits,2visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

EmailEmail
PrintPrint