What is the method for converting a list to a set in Java?
In Java, you can use the constructor of Set to convert a List to a Set. For example:
List<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("orange");
Set<String> set = new HashSet<>(list);
This allows the elements in the List to be transformed into elements in the Set. You can use different implementations of Sets such as HashSet, TreeSet, etc. to create different Set collections.