Initialize a static map in Java with Examples Last Updated : 27 Oct, 2021 Comments Improve Suggest changes Like Article Like Report In this article, a static map is created and initialized in Java. A static map is a map which is defined as static. It means that the map becomes a class member and can be easily used using class. Method 1: Creating a static map variable. Instantiating it in a static block. Below is the implementation of the above approach: Java // Java program to create a static map import java.util.*; class GFG { // Declaring the static map private static Map<Integer, String> map; // Instantiating the static map static { map = new HashMap<>(); map.put(1, "GFG"); map.put(2, "Geek"); map.put(3, "GeeksForGeeks"); } // Driver code public static void main(String[] args) { System.out.println(map); } } Output: {1=GFG, 2=Geek, 3=GeeksForGeeks} Method 2: Creating a static map variable and instantiating it together. Below is the implementation of the above approach: Java // Java program to create a static map import java.util.*; class GFG { // Declaring the static map private static Map<Integer, String> map = new HashMap<>() { map.put(1, "GFG"); map.put(2, "Geek"); map.put(3, "GeeksForGeeks"); } // Driver code public static void main(String[] args) { System.out.println(map); } } Output: {1=GFG, 2=Geek, 3=GeeksForGeeks} Comment More infoAdvertise with us Next Article Initialize a static map in Java with Examples C code_r Follow Improve Article Tags : Java Static Keyword java-map Practice Tags : Java Similar Reads Static Method in Java With Examples In Java, the static keyword is used to create methods that belongs to the class rather than any specific instance of the class. Any method that uses the static keyword is referred to as a static method.Features of Static Method:A static method in Java is associated with the class, not with any objec 3 min read Initialize a static Map using Stream in Java In this article, a static map is created and initialized in Java using Stream. Static Map in Java A static map is a map which is defined as static. It means that the map becomes a class member and can be easily used using class. Stream In Java Introduced in Java 8, the Stream API is used to process 2 min read Map.Entry interface in Java with example Map.Entry interface in Java provides certain methods to access the entry in the Map. By gaining access to the entry of the Map we can easily manipulate them. Map.Entry is a generic and is defined in the java.util package. Declaration : Interface Map.Entry k -> Key V -> Value Methods: equals (O 4 min read Map isEmpty() Method in Java with Examples This method is used to check if a map is having any entry for key and value pairs. If no mapping exists, then this returns true. Syntax: boolean isEmpty() Parameters: This method has no argument. Returns: This method returns True if the map does not contain any key-value mapping. Below programs show 1 min read Initialize a static Map using Java 9 Map.of() In this article, a static map is created and initialised in Java using Java 9. Static Map in Java A static map is a map which is defined as static. It means that the map becomes a class member and can be easily used using class. Java 9 feature - Map.of() method In Java 9, Map.of() was introduced whi 2 min read Map put() Method in Java with Examples The Map put() method associates the specified value with the specified key in the map. The map put() method is used to insert new key-value pairs inside a map in Java. If the map already contains the mapping for the specified key, the old value is replaced by the new specified value. Example: Java / 3 min read Map clear() method in Java with Example The java.util.Map.clear() method in Java is used to clear and remove all of the elements or mappings from a specified Map collection. Syntax: void clear() Parameters: The method does not accept any parameters. Return Value: The method does not return any value. Below programs are used to illustrate 2 min read Map size() Method in Java With Examples Map size() method in Java is used to get the total number entries i.e, key-value pair. So this method is useful when you want total entries present on the map. If the map contains more than Integer.MAX_VALUE elements returnInteger.MAX_VALUE Syntax: int size(); Parameter: This method does not take an 1 min read Initialize a static Map in Java using Double Brace Initialization In this article, a static map is created and initialised in Java using Double Brace Initialization. Static Map in Java A static map is a map which is defined as static. It means that the map becomes a class member and can be easily used using class. Double Brace Initialization In Double Brace Initia 2 min read Map putAll() Method in Java with Examples This method is used to copy all of the mappings from the specified map to this map. Syntax: void putAll(Map m) Parameters: This method has the only argument map m, which contains key-value mappings to be copied to given map. Returns: This method returns previous value associated with the key if pres 2 min read Like