当前位置: 动力学知识库 > 问答 > 编程问答 >

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

问题描述:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: