摘要
Java平台提供了多种方式遍历对象的集合,其中包括今年3月19日发布的Java 8中引入的新特性。本文回顾了迭代器,着重分析了主动式迭代器和被动式迭代器之间的差异,研究了Java 8的foreach()方法和Stream API如何改进和并行化Java迭代器的行为,然后对主动迭代、流和并行流这三种方法进行了性能比较。总之,Java 8的迭代器可读性更好,不易出错,也更容易并行化。
The Java platform provides a variety of ways to iterate over a collection of objects,including new features in Java 8,which was released at March 19 this year.This article revisits the difference between active and passive iterators.Study how Java 8's forEach() method and the Stream API can improve and parallelize the behavior of Java iterators,then conclude with some performance test.
出处
《软件工程师》
2014年第10期42-44,共3页
Software Engineer