How to Create Empty Map with the emptyMap() in Java


The example will prompt user to create an empty map with the emptyMap() method.

Source Code

package com.beginner.examples;

import java.util.Collections;
import java.util.Map;
 
public class EmptyMapExample {
 
    public static void main(String a[]){
        // use emptyMap()
        Map map = Collections.emptyMap();
        System.out.println("Map: " + map);
    }
}

Output:

Map: {}

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments