Getting Set View of Keys from HashMap in Java Last Updated : 19 Feb, 2021 Comments Improve Suggest changes Like Article Like Report The HashMap class of Java provides the functionality of the hash table data structure. This class is found in the java.util package. It implements the Map interface. It stores elements in (Key, Value) pairs and you can access them by an index of another type (e.g. Integer/String). Here, keys are used as identifiers which are used to associate each value on a map. It can store different types: Integer keys and String values or same types: Integer keys and Integer values. Example: Given : HashMap = {[a, 1], [b, 3], [C, 1]} Output: Keys = [a, b, c] Given : HashMap<Key, Value> = {[2, "hello"], [1, "world"]} Output: Keys = [2, 1]HashMap is similar to HashTable, but it is unsynchronized. It is allowed to store null keys as well, but there can only be one null key and there can be any number of null values. HashMap <Integer,String> GFG = new HashMap <Integer,String>(); // Above is the declaration of HashMap object with Integer keys and String values The Set interface present in java.util package is an unordered collection of objects in which duplicate values cannot be stored Set <Obj> set = new HashSet<Obj>( ); // Obj is the type of object to be stored in the SetThe Set view of the keys from HashMap returns the set of all keys in the HashMap in the form of a Set. Print Keys: Using Iterator object print all keys from while loopPrint set object directly passing in System.out.println().Implementation: Java // Getting Set view of keys from HashMap in Java import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { HashMap<Integer, String> GFG = new HashMap<Integer, String>(); // Inserting 1 as key and Geeks as the value GFG.put(1, "Geeks"); // Inserting 2 as key and For as the value GFG.put(2, "For"); // Inserting 3 as key and Geeks as the value GFG.put(3, "Geeks"); Set<Integer> Geeks = GFG.keySet(); System.out.println("Set View of Keys in HashMap : " + Geeks); } } OutputSet View of Keys in HashMap : [1, 2, 3] Comment More infoAdvertise with us Next Article Getting Set View of Keys from HashMap in Java deepthimgs Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-HashMap +1 More Practice Tags : Java Similar Reads Getting Synchronized Map from Java HashMap HashMap is a non synchronized collection class. If we want to perform thread-safe operations on it then we must have to synchronize it explicitly. In order to synchronize it explicitly the synchronizedMap() method of java.util.Collections class is used to return a synchronized (thread-safe) map back 2 min read Creating HashMap from Other Maps in Java Map interface present in java.util package represents a mapping between a key and a value. The Map interface is not a subtype of the Collection interface. Therefore, it behaves a bit differently from the rest of the collection types. A map contains unique keys. There are three main types of maps in 3 min read Convert HashMap to LinkedList in Java HashMap is similar to the HashTable, but it is unsynchronized. It allows to store the null keys as well, but there should be only one null key object and there can be any number of null values. LinkedList is a part of the Collection framework present in java.util package. This class is an implementa 2 min read Java Program to Sort a HashMap by Keys and Values HashMap<K, V> is a Java Collection and is a part of java.util package. It provides the basic implementation of the Map interface of Java. It stores the data in the form of Key, Value pairs, where the keys must be unique but there is no restriction for values. If we try to insert the duplicate 3 min read How to Convert Two Arrays Containing Keys and Values to HashMap in Java? HashMap is part of the Collections framework of java. It stores the data in the form of key-value pairs. These values of the HashMap can be accessed by using their respective keys or the key-value pairs can be accessed using their indexes (of Integer type). HashMap is similar to Hashtable in java. T 2 min read Program to Convert HashMap to TreeMap in Java HashMap is a part of Javaâs collection since Java 1.2. It provides the basic implementation of Map interface of Java which stores the data in (Key, Value) pairs. To access a value in HashMap, one must know its key. HashMap is known as HashMap because it uses a technique Hashing for storage of data. 6 min read Check if Particular Key Exists in Java HashMap HashMap in Java is the realization of the Hash Table data structure of sorts. It is composed of Key and Value pairs which are symbolically represented as <K,V> where K stands for Key and V for Value. It is an implementation of the Maps Interface and is advantageous in the ways that it provides 5 min read Traverse Through a HashMap in Java HashMap stores the data in (Key, Value) pairs, and you can access them by an index of another type. HashMap class implements Map interface which allows us to store key. hashMap is a part of the java collections framework been up since Java 1.2. It internally uses hashing technique which is pretty fa 4 min read How to Get All the Values of the LinkedHashMap in Java? LinkedHashMap is a predefined class in Java that is similar to HashMap, contains key and its respective value, unlike HashMap. In LinkedHashMap insertion order is preserved. The task is to get all the values present in our LinkedHashMap that is linked with their respective key. Use Iteration or pred 4 min read How to Get a Value From LinkedHashMap by Index in Java? LinkedHashMap is a predefined class in Java which is similar to HashMap, contain key and its respective value unlike HashMap, In LinkedHashMap insertion order is preserved. The task is to get value from LinkedHashMap by their Index in other words, an order of their insertion. As an advantage of Link 4 min read Like