Initialize a static Map in Java using Double Brace Initialization Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Initialization: The first brace creates a new Anonymous Inner Class. These inner classes are capable of accessing the behaviour of their parent class. So, in our case, we are actually creating a subclass of HashMap class, so this inner class is capable of using put() method. The second braces are instance initializers. The code an instance initializers inside is executed whenever an instance is created. Approach: Pass the map values as Key and Value pair in the Double braces. A static factory Map instance is returned. Store it in Map and use. Below is the implementation of the above approach: Example 1: Java // Java program to create a static map // using Double Brace Initialization import java.util.*; class GFG { // Declaring and instantiating the static map // using Double Brace Initialization private static Map<String, String> map = new HashMap<String, String>() {{ put("1", "GFG"); put("2", "Geek"); put("3", "GeeksForGeeks"); }}; // Driver code public static void main(String[] args) { System.out.println(map); } } Output: {1=GFG, 2=Geek, 3=GeeksForGeeks} Example 2: To show with 10 key-value pairs Java // Java program to create a static map // using Double Brace Initialization import java.util.*; class GFG { // Declaring and instantiating the static map // using Double Brace Initialization private static Map<String, String> map = new HashMap<String, String>() {{ put("1", "GFG"); put("2", "Geek"); put("3", "GeeksForGeeks"); put("4", "G"); put("5", "e"); put("6", "e"); put("7", "k"); put("8", "s"); put("9", "f"); put("10", "o"); }}; // Driver code public static void main(String[] args) { System.out.println(map); } } Output: {1=GFG, 2=Geek, 3=GeeksForGeeks, 4=G, 5=e, 6=e, 7=k, 8=s, 9=f, 10=o} Related Articles: Initialize a static map in Java with Examples Initialize a static Map using Stream in Java Initialize a static Map using Java 9 Map.of() Comment More infoAdvertise with us Next Article How to Declare and Initialize an Array in Java? C code_r Follow Improve Article Tags : Java Static Keyword java-map Practice Tags : Java Similar Reads Double Brace Initialization in Java The combination of two separate processes in Java is known as Double Brace Initialization in Java. As the name suggests, there are two braces {{ included in it. A single brace { is nothing new for programmers. The first brace in the double brace initialization is used to create an anonymous inner cl 4 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 Initialize a static map in Java with Examples 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 implementati 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 How to Declare and Initialize an Array in Java? An array in Java is a linear data structure that is used to store multiple values of the same data type. In an array, each element has a unique index value, which makes it easy to access individual elements. We first need to declare the size of an array because the size of the array is fixed in Java 5 min read How to initialize a list in a single line in Java with a specified value? Given a value N, the task is to create a List having this value N in a single line in Java. Examples: Input: N = 5 Output: [5] Input: N = GeeksForGeeks Output: [GeeksForGeeks] Approach: Get the value N Create an array with this value N Create a List with this array as an argument in the constructor 2 min read Like