Tagged: #map

How to iterate a Map in Java

This tutorial shows several ways for iterating a Map in Java. 1- Entry Set The common way for iterating a Map in Java is through entrySet() method as the following:

2- Iterator You can also use entrySet() along with iterator() methods to iterate a Map through an Iterator:

3- keySet() Using keySet() method, you can retrieve all the...

Java – Convert List to Map

This tutorial shows the different ways to convert a List to Map in Java. 1- Java 7 & before With Java 7 and older releases, the only way to convert a List to Map is to iterate over the list and populate the map manually. In the following example, we implement a utility method which accepts a list of Student...