课程: Learning Java Collections

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Iterating collection elements

Iterating collection elements

- [Instructor] When working with Java Collections, it's common to traverse or iterate through each element in the collection, one after the other. Initially, the framework provided an iterator for the task, or a basic loop was used. Then, new versions of Java introduced language features like the enhanced for-each loop, and streams that gave us new approaches for navigating collection elements. At a high level, we can categorize the approaches for traversing a collection into three groups, loops, iterables, and streams. First let's talk about loops. These are the trusted while, do-while, and for loops that we learned when starting out with Java. They can be used to iterate collection implementations that allow positional or reference-based access to the elements that they hold. You'll notice I've placed for-each loops into this group. Using its concise syntax requires the object we are traversing to implement the iterable…

内容