Scala 中迭代器和流之间的区别? [英] Difference between Iterator and Stream in Scala?

查看:36
本文介绍了Scala 中迭代器和流之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Iterator 和 Stream 似乎都是懒惰的,允许您不断将元素返回到您的内心深处.两者有什么区别?

It seems that both Iterator and Stream are lazy and allow you to keep returning elements to your heart's content. What's the difference between the two?

推荐答案

Stream memoises 和 Iterator才不是.您可以多次遍历同一个 Stream 并且每次都得到相同的结果.另一方面,迭代器只能被遍历一次.

Stream memoises and Iterator does not. You can traverse the same Stream multiple times and get the same result each time. Iterator, on the other hand, can only be traversed once.

这篇关于Scala 中迭代器和流之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆