I have an Enumeration object and I want to create a Collection object containing the items of the enumeration.
Is there any Java function to do this without manually iterating over the enumeration? Something like the reverse of the Collections.enumeration
method?
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);
In fact, there is Collections.list(enumeration)
(There is also EnumerationUtils.toList(enumeration)
from commons-collections.)
There's nothing in the standard API, because Enumerations and Iterators are not considered first-class API entities as in the C++ STL. You're supposed to consume them immediately after creation (ideally implicitly via the "enhanced for loop").
Collections.list()
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