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).
In order to get enumeration over ArrayList with Java Collections, we use the java. util. Collections. enumeration() method.
Enumeration[] array = Enumeration. values(); List<Enumeration> list = Arrays. asList(array);
The idea is to use the Enum. GetValues() method to get an array of the enum constants' values. To get an IEnumerable<T> of all the values in the enum, call Cast<T>() on the array. To get a list, call ToList() after casting.
An enumerated set is a finite or countable set or multiset S together with a canonical enumeration of its elements; conceptually, this is very similar to an immutable list.
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));
How about this: Collections.list(Enumeration e) returns an ArrayList<T>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With