From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Managing unordered data with HashMap - Java Tutorial
From the course: Java 8 Essential Training
Managing unordered data with HashMap
- I've described how to use an array list to manage an ordered set of data. And now I'll show you how to use a hash map to represent an unordered data collection. Just as with an array list, which implements the list interface, a hash map is an implementation of an interface named Map. And typically you'll see code like this. I'm going to declare a collection of states. Each item in a map is a key value pair. The data types of each of these can be anything you want, but frequently you'll see that the key is a string, and then the second value might be a number, a string, or any other sort of complex object. When I select Map, I get the import statement. And then, just as with a list, I use the diamond operator to declare the data types of my keys and my values. So I need two data types. And these will both be strings. I'll name my object Map, and then I'll initialize it with new. And then I'll use the concrete implementation of the Map interface named HashMap. Just as with the generic…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.