Hashmap
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); HashMap<String, Integer> ages = new HashMap<>(); ages.put("Tom", 22); ages.put("Nick", 30); ages.put("Eric", 44); String[] nameArr = new String[ages.size()]; nameArr = ages.keySet().toArray(nameArr); int ageLimit = sc.nextInt(); for (String emp : nameArr) { if ( ages.get(emp) < ageLimit) { ages.remove(emp); } } System.out.println(ages); } } Guys, for what I need the String " nameArr = ages.keySet().toArray(nameArr); " ? It get only the key word from hashmap and add it to array "nameArr"?