Java HashMap Iteration over Values Example

This example shows how to iterate only over values of a HashMap in Java with an example.

Java HashMap Iteration over Values Example

package com.javaguides.collections.hashmapexamples;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

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);

        Collection<Double> vlaues = employeeSalary.values();

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

Output

76000.0
120000.0
95000.0
134000.0

Comments