Initialize a static map in Java with Examples Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share 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 Map.Entry interface in Java with example 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 Like