- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to convert Set to List in Java
Let’s say the following is our Set with string values −
Set<String> set = new HashSet<String>(); set.add("Laptop"); set.add("Mobile"); set.add("Tablet"); set.add("LCD"); set.add("LED");
Now, let us convert it to List −
List<String> list = new ArrayList<>(set);
Following is the program to convert Set to List in Java −
Example
import java.util.*; import java.util.stream.*; public class Demo { public static void main(String args[]) { Set<String> set = new HashSet<String>(); set.add("Laptop"); set.add("Mobile"); set.add("Tablet"); set.add("LCD"); set.add("LED"); set.add("Desktop"); System.out.println("Set = " + set); List<String> list = new ArrayList<>(set); System.out.println("List = " + list); } }
Output
Set = [Laptop, Desktop, Tablet, LED, LCD, Mobile] List = [Laptop, Desktop, Tablet, LED, LCD, Mobile]
- Related Articles
- Java Program to convert a List to a Set
- Convert List to Set in Java
- Haskell Program to Convert List to Set
- C++ Program to Convert List to Set
- Golang Program to Convert List to Set
- Convert a List to a Set in Java
- Program to convert Array to Set in Java
- Program to convert List to Stream in Java
- Program to convert Array to List in Java
- How can we convert list to Set in Java?
- How to convert a Java list to a set?
- Java Program to convert Stream to List
- Program to convert a Vector to List in Java
- Can we convert a list to a Set in Java?
- Java program to convert an Array to Set

Advertisements