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

919total visits,12visits today


mayank

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

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image