[api] Convert Enumeration to a Set/List

Is there some one-liner bridge method to dump a given Enumeration to java.util.List or java.util.Set?

Something built-in like Arrays.asList() or Collection.toArray() should exist somewhere, but I'm unable to find that in my IntelliJ debugger's evaluator window (and Google/SO results, too).

This question is related to api collections conventions java

The answer is

You can use Collections.list() to convert an Enumeration to a List in one line:

List<T> list = Collections.list(enumeration);

There's no similar method to get a Set, however you can still do it one line:

Set<T> set = new HashSet<T>(Collections.list(enumeration));

Similar questions with api tag:

Similar questions with collections tag:

Similar questions with conventions tag:

Similar questions with java tag: