Initialize a static Map using Stream in Java Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 collections of objects. A stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result. Approach: Create a stream and insert 2D values as Key and Value pair in it. These values will be later used to instantiate the Map. Using the collect() method of Stream, map the values from the stream to the map. This can be done with the help of Collectors.toMap() method and the keyMapper and ValueMapper respectively. Below is the implementation of the above approach: Java // Java program to create a static map using Stream import java.util.*; import java.util.stream.Collectors; class GFG { // Declaring and instantiating the static map private static Map<String, String> map = Arrays.stream(new String[][] { { "1", "GFG" }, { "2", "Geek" }, { "3", "GeeksForGeeks" } }) .collect(Collectors.toMap( keyMapper -> keyMapper[0], valueMapper -> valueMapper[1])); // Driver code public static void main(String[] args) { System.out.println(map); } } Output: {1=GFG, 2=Geek, 3=GeeksForGeeks} Create Quiz Comment C code_r Follow 0 Improve C code_r Follow 0 Improve Article Tags : Java java-stream java-map Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like