我最近了解到,遍历集合聚合操作是比 for-each 构造或迭代器更好的选择,但我不知道如何实现。 获取流并执行聚合操作有什么好处。 是否存在任何性能问题或只是语法简单?
最佳答案
聚合操作和迭代器(或 for-each 循环)之间的主要区别之一是前者使用内部迭代。正如 Oracle 文档所说:
"external iteration can only iterate over the elements of a collection sequentially. Internal iteration does not have this limitation. It can more easily take advantage of parallel computing". Ref: https://docs.oracle.com/javase/tutorial/collections/streams/index.html#differences
关于java - 要遍历集合,聚合操作是更好的选择如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38662248/