Java8 stream operations are cached? [duplicate]

我的未来我决定 提交于 2019-12-06 10:50:36

does it mean stream operations are cached?

No, the code generated to implement the lambdas, and the classes loaded are cached.

Is there any internal cache implemented for streams in Java8?

There is no special cache for Streams.

sometimes findAny returns different value but the time taken is almost equal to the subsequent runs not like the first run

Indeed. Nothing about the result is cached. The first time you pay a penalty for loading the code.

BTW the coding isn't really optimised until it has been run at least 10,000 times. I would run this test repeatedly for around 10 seconds before timing it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!