Dictionary keys() Method in Java with Examples Last Updated : 27 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The keys() method of Dictionary class in Java is used to get the enumeration of the keys present in the dictionary. Syntax: Enumeration enu = DICTIONARY.keys() Parameters: The method does not take any parameters. Return value: The method returns an enumeration of the keys of the Dictionary. Below programs are used to illustrate the working of the java.util.Dictionary.keys() method: Program 1: Java // Java code to illustrate the keys() method import java.util.*; public class Dictionary_Demo { public static void main(String[] args) { // Creating an empty Dictionary Dictionary<Integer, String> dict = new Hashtable<Integer, String>(); // Inserting elements into the Dictionary dict.put(10, "Geeks"); dict.put(15, "4"); dict.put(20, "Geeks"); dict.put(25, "Welcomes"); dict.put(30, "You"); // Displaying the Dictionary System.out.println("The Dictionary is: " + dict); // Creating an empty enumeration to store Enumeration enu = dict.keys(); System.out.println("The enumeration of keys are:"); // Displaying the Enumeration while (enu.hasMoreElements()) { System.out.println(enu.nextElement()); } } } Output: The Dictionary is: {10=Geeks, 20=Geeks, 30=You, 15=4, 25=Welcomes} The enumeration of keys are: 10 20 30 15 25 Program 2: Java // Java code to illustrate the keys() method import java.util.*; public class Dictionary_Demo { public static void main(String[] args) { // Creating an empty Dictionary Dictionary<String, Integer> dict = new Hashtable<String, Integer>(); // Inserting elements into the table dict.put("Geeks", 10); dict.put("4", 15); dict.put("Geeks", 20); dict.put("Welcomes", 25); dict.put("You", 30); // Displaying the Dictionary System.out.println("The Dictionary is: " + dict); // Creating an empty enumeration to store Enumeration enu = dict.keys(); System.out.println("The enumeration of keys are:"); // Displaying the Enumeration while (enu.hasMoreElements()) { System.out.println(enu.nextElement()); } } } Output: The Dictionary is: {You=30, Welcomes=25, 4=15, Geeks=20} The enumeration of keys are: You Welcomes 4 Geeks Comment More infoAdvertise with us Next Article Dictionary keys() Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-Dictionary +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Dictionary get() Method in Java with Examples The get() method of Dictionary class is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. It returns NULL when the dictionary contains no such mapping for the key. Syntax: DICTIONARY.get(Object key_element) Parameters: The method takes one parameter key_eleme 2 min read Dictionary put() Method in Java with Examples The put() method of Dictionary is used to insert a mapping into the dictionary. This means a specific key along with the value can be mapped into a particular dictionary. Syntax: DICTIONARY.put(key, value) Parameters: The method takes two parameters, both are of the Object type of the Dictionary. ke 2 min read Dictionary size() Method in Java with Examples The size() Method of Dictionary class in Java is used to know the size of the dictionary or the number of distinct keys present in the dictionary. Syntax: DICTIONARY.size() Parameters: The method does not accept any parameters. Return Value: The method returns the number of keys present in the dicti 2 min read Dictionary elements() Method in Java with Examples The keys() method of Dictionary class in Java is used to get the enumeration of the values present in the dictionary. Syntax: Enumeration enu = DICTIONARY.elements() Parameters: The method does not take any parameters. Return value: The method returns an enumeration of the values of the Dictionary. 2 min read Collections list() method in Java with Examples The list() method of java.util.Collections class is used to return an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration. This method provides interoperability between legacy APIs that return enumerations and new APIs that requi 2 min read Collection add() Method in Java with Examples The add(E element) of java.util.Collection interface is used to add the element 'element' to this collection. This method returns a boolean value depicting the successfulness of the operation. If the element was added, it returns true, else it returns false. Syntax: Collection.add(E element) Paramet 4 min read Map keySet() Method in Java with Examples This method is used to return a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. Example:Java// Java Program Implementing Map // keySet() Method import java.util.*; public class GfG { public static void main(Str 2 min read Map containsKey() method in Java with Examples The java.util.Map.containsKey() method is used to check whether a particular key is being mapped into the Map or not. It takes the key element as a parameter and returns True if that element is mapped in the map. Syntax: boolean containsKey(key_element) Parameters: The method takes just one paramete 2 min read List add() Method in Java with Examples The List add() method adds (appends) an element to a list. It can be used for both ArrayList and LinkedList. Example of List add() Method: Java // Java program to demonstrate // ArrayList usage import java.io.*; import java.util.ArrayList; import java.util.List; class GFG { public static void main ( 3 min read Collection contains() method in Java with Examples The contains(Object element) of java.util.Collection interface is used to check whether the element 'element' exists in this collection. This method returns a boolean value depicting the presence of the element. If the element is present, it returns true, else it returns false. Syntax: Collection.co 3 min read Like