2017-11-17 260 views
0

我最好的解决方案是目前:从java流中创建java.util.Enumeration的最佳方式是什么?

Collections.enumeration(stream.collect(Collectors.toList())) 

盼望比这更简洁的方法。

+3

更多_concise_?不见得。 _可能会更有效率。 –

+0

只是静态导入enumaration和toList,它变成了'enumeration(stream.collect(toList()))'你也可以使用joo-lambda Seq来代替Stream并且它变成'enumeration(seq.toList())';虽然shmosel的答案似乎是专门为这个用例制作的 – Novaterata

+2

有没有可能你不需要枚举?这是相当古老的类型,即使在它的文档中指出:“*新的实现应该考虑使用'Iterator'而不是'Enumeration' *”。也许这是又一个[X/Y问题]的案例(https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。 – Pshemo

回答

相关问题