Convert List to a Set / Set to List in Java

In Java, When we are working on real time projects.. Generally we came across scenarios like Converting List to Set Object or Vice Versa.

1. Converting a List to a Set Object.
Set<Foo> urSet= new HashSet<Foo>(YourList);
2. Converting a Set to a List Object.
myList.addAll(YourSet);

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s