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
Related HashMap Source Code Examples
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course