
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How do you create a list from a set in Java?
We can create a list from a set using its constructor.
List<Integer> list = new ArrayList<Integer>(set);
Example
Following is the example showing the conversion of set to list −
package com.tutorialspoint; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class CollectionsDemo { public static void main(String[] args) { Set<Integer> set = new HashSet<>(); set.add(1); set.add(2); set.add(3); set.add(4); System.out.println("Set: " + set); List<Integer> list = new ArrayList<>(set); System.out.println("List: " + list); } }
Output
This will produce the following result −
Set: [1, 2, 3, 4] List: [1, 2, 3, 4]
- Related Articles
- How do you create a list in Java?
- How do you turn a list into a Set in Java?
- How do you create a list with values in Java?
- How do you create an empty list in Java?
- How do you copy a list in Java?
- How do you make a list iterator in Java?
- How do you remove duplicates from a list in Python?
- How do you make a shallow copy of a list in Java?
- How do you turn an ArrayList into a Set in Java?
- How do you remove multiple items from a list in Python?
- How do you add an element to a list in Java?
- How do you check a list contains an item in Java?
- How do I set the size of a list in Java?
- How do you create a date object from a date in Swift xcode?
- How do you copy an element from one list to another in Java?

Advertisements