This post originated from an RSS feed registered with Java Buzz
by Arpit Mandliya.
Original Post: How to convert List to Set in java
Feed Title: Java tutorial for beginners
Feed URL: http://feeds.feedburner.com/arpitmandliyasblog
Feed Description: A blog about java programming language and its frameworks
In this post, we will see how to convert List to Set in java.We will convert ArrayList to HashSet. As HashSet does not allow duplicates, when you convert ArrayList to HashSet, all the duplicates will be discarded. You can simply use the constructor of HashSet to convert ArrayList to HashSet. Here is simple example: When you run above program, you will get below output ======================= List of Countries: ======================= India China Bhutan Nepal India ======================= Set of Countries: ======================= Bhutan China Nepal India Java 8 list of set example You can use Java 8 Stream API to convert