There are two methods used to convert a set to a list:
import java.util.*;import java.util.stream.*;class example {// Generic function to convert set to listpublic static <T> List<T> convertSetToList(Set<T> set){// create an empty listList<T> list = new ArrayList<>();// push each element in the set into the listfor (T t : set)list.add(t);// return the listreturn list;}public static void main(String args[]){// Create a Set using HashSetSet<String> hash_Set = new HashSet<String>();// Add elements to sethash_Set.add("Educative's");hash_Set.add("example");hash_Set.add("Set");hash_Set.add("to");hash_Set.add("list");// Print the SetSystem.out.println("Set: " + hash_Set);// construct a new List from SetList<String> list = convertSetToList(hash_Set);// Print the ListSystem.out.println("List: " + list);}}
import java.util.*;import java.util.stream.*;class example {// Generic function to convert set to listpublic static <T> List<T> convertSetToList(Set<T> set){// create a list from SetList<T> list = new ArrayList<>(set);// return the listreturn list;}public static void main(String args[]){// Create a Set using HashSetSet<String> hash_Set = new HashSet<String>();// Add elements to sethash_Set.add("Educative's");hash_Set.add("example");hash_Set.add("Set");hash_Set.add("to");hash_Set.add("list");// Print the SetSystem.out.println("Set: " + hash_Set);// construct a new List from SetList<String> list = convertSetToList(hash_Set);// Print the ListSystem.out.println("List: " + list);}}