/**
* @author lautturi.com
* Java example: get the keys from hashmap and put them into a list in java
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
Map<Integer, String> map = new HashMap<Integer, String>() {{
put(5,"Apple");
put(7,"Banana");
put(12,"Cherry");
put(33,"Orange");
put(23,"Lautturi");
}};
List<Integer> list = new ArrayList<Integer>(map.keySet());
System.out.println("List of keys: " + list);
}
}
output:
List of keys: [33, 5, 7, 23, 12]