This Java program demonstrates how to get the keys of a HashMap collection using the keySet() method. Here is a step-by-step explanation of the program:
import java.util.*; public class Get_Keys { public static void main(String[] args) { HashMap < Integer, String > stu = new HashMap < > (); stu.put(101, "Kim"); stu.put(102, "Arun"); stu.put(103, "Deepika"); stu.put(104, "Ramesh"); stu.put(105, "Joes"); stu.put(106, "Abi"); stu.put(107, "John"); stu.put(108, "Vijay"); stu.put(109, "Suga"); stu.put(110, "Siva"); Set < Integer > keys = stu.keySet(); System.out.println("Keys from a HashMap Collection .."); for (Integer key: keys) { System.out.println(key); } } }
Keys from a HashMap Collection .. 101 102 103 104 105 106 107 108 109 110
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions