This program uses a HashMap to store key-value pairs of Integer and String data types. It then retrieves a Set view of the keys in the HashMap using the keySet() method, and prints the Set view to the console.
import java.util.*; public class GetSet_ViewKeys { public static void main(String args[]) { HashMap<Integer,String> hash_map = new HashMap<Integer,String>(); hash_map.put(1, "Blue"); hash_map.put(2, "Green"); hash_map.put(3, "Pink"); hash_map.put(4, "White"); hash_map.put(5, "Red"); hash_map.put(6, "Black"); hash_map.put(7, "Orange"); Set keyset = hash_map.keySet(); System.out.println("Key set values are : " + keyset); } }
Key set values are : [1, 2, 3, 4, 5, 6, 7]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions