37    Working with Map

After reading this lesson, you will be able to:

  • Retrieve the value associated with a key
  • Get all keys and all values stored in a Map
  • Check its size and the feature of its entries
  • Filter its elements based on given criteria

In the previous lesson, you have learned about the basics of Map. In this lesson, you’ll master the most common operations you can apply to it. You’ll use different strategies to retrieve a value linked to a given key. You’ll get all the keys and all the values in an instance of a Map. Finally, you will get its size, inquire of the properties of its entries, and filter its elements according to their characteristics by reusing the same methods you have seen for List and Set. In the capstone, you will apply these operations to extract the book information from a CSV file and create the book collection of your library.

37.1       Retrieving a value for a given key

Consider the program to track the exam registration that you are implementing. Imagine you now need to retrieve all the students that have enrolled for a given exam session. Listing 37.1 shows you how to do that:

37.2       Getting all keys and values

37.3       Other Operations on Map

37.4       Summary

37.5       Answers to Quick Checks