课程: Learning Java Collections

今天就学习课程吧!

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

Iterating Maps

Iterating Maps

- [Instructor] Traversing each entry in a map can be challenging when first learning about collections. So let me show you how it works. To do that, I'm going to start out by invoking the entrySet method on our map, and I'm actually going to assign this to a variable so you can see the typing of the object returned. Now, as its name implies, the entrySet is a set that contains entries. Now, the entry itself is a generic type. So first, we need to specify the type of the key used for our map and then the type of the values used for our map. All right, so now we have the type of our variable and I'm just going to name it CV for collection view. Now, let's talk about this for one minute. You'll notice that the returned object is a set, so that means it extends the collection interface and it also extends the iterable interface. So we can use this set within the enhanced for-each loop and that's typically how the entrySet is…

内容