2017-11-17 258 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

回答

相關問題