Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Retrieve all the keys from HashMap in Java

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
public class Demo {
	public static void main(String[] args) {
		HashMap<Integer, String>map = new HashMap<Integer, String>();
		map.put(10, "A");
		map.put(20, "B");
		map.put(30, "C");
		map.put(40, "D");
		map.put(50, "E");
		map.put(60, "F");
		map.put(70, "G");
		map.put(80, "H");
		Set<Integer>set = map.keySet();
		Iterator<Integer>i = set.iterator();
		while (i.hasNext()) {
			Integer res = i.next();
			System.out.println(res + ": " + map.get(res));
		}
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.