Java HashMap Iteration over Keys

This example shows how to iterate over only keys of HashMap with an example.

Java HashMap Iteration over Keys

package com.javaguides.collections.hashmapexamples;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class IterateOverHashMap {
    public static void main(String[] args) {
        Map<String, Double> employeeSalary = new HashMap<>();
        employeeSalary.put("David", 76000.00);
        employeeSalary.put("John", 120000.00);
        employeeSalary.put("Mark", 95000.00);
        employeeSalary.put("Steven", 134000.00);

        Set<String> keys = employeeSalary.keySet();

        keys.forEach(System.out::println);        
    }
}

Output

David
John
Mark
Steven


Comments