Hi@MD,
The most straightforward way to convert a set to a list is bypassing the set as an argument while creating the list. This calls the constructor and from there onwards the constructor takes care of the rest.
import java.util.*;
public class Main {
public static void main(String[] args)
{
Set<Integer> a = new HashSet<>();
a.add(1);
a.add(2);
a.add(3);
a.add(1);
List<Integer> arr = new ArrayList<>(a);
System.out.println(arr);
System.out.println(arr.get(1));
}
}
Hope this helps!
Check out java certification course to learn more.
Thanks!