开发者

Is there a one-liner to create a Collection from an Enumeration object?

开发者 https://www.devze.com 2023-01-31 10:18 出处:网络
I have an Enumeration object and I want to create a Collection object containing the items of the enumeration.

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 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()

0

精彩评论

暂无评论...
验证码 换一张
取 消