- 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
Convert a Set into a List in Java
First, create a Set and add elements −
Set<Object> s = new HashSet<Object>(); s.add("P"); s.add(new Date()); s.add(new Long(898999)); s.add("Q"); s.add("R"); s.add(new Integer(1));
Convert the above Set to a List −
List<Object> l = new ArrayList<Object>(s);
The following is an example to convert a set into a list in Java −
Example
import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Set; import java.util.HashSet; public class Demo { public static void main(String[] args) { Set<Object> s = new HashSet<Object>(); s.add("P");; s.add(new Date()); s.add(new Long(898999)); s.add("Q"); s.add("R"); s.add(new Integer(1)); List<Object> l = new ArrayList<Object>(s); for (int i = 0; i < l.size(); i++) { Object ob = l.get(i); System.out.println(ob); } } }
Output
P Q 1 R Sat Jan 05 07:34:56 UTC 2019 898999
- Related Articles
- Convert set into a list in Python
- Convert a List to a Set in Java
- Can we convert a list to a Set in Java?
- Java Program to convert a List to a Set
- How to convert a Java list to a set?
- How to convert a list collection into a dictionary in Java?
- Java Program to convert a set into an Array
- How do you turn a list into a Set in Java?
- Convert List to Set in Java
- Java Program to convert Properties list into a Map
- Java program to convert a list of characters into a string
- Convert a nested list into a flat list in Python
- Can we convert a List to Set and back in Java?
- Python - Convert a set into dictionary
- Convert String into comma separated List in Java

Advertisements