Home » Java programming language

Java Collections emptyMap() Method with Example

Collections Class emptyMap() method: Here, we are going to learn about the emptyMap() method of Collections Class with its syntax and example.
Submitted by Preeti Jain, on February 08, 2020

Collections Class emptyMap() method

  • emptyMap() method is available in java.util package.
  • emptyMap() method is used to return the immutable empty Map.
  • emptyMap() method is a static method, so it is accessible with the class name and if we try to access the method with the class object then also we will not get an error.
  • emptyMap() method does not throw an exception at the time of returning an empty immutable map.

Syntax:

    public static final Map emptyMap();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is Map, it returns an immutable empty map.

Example:

// Java program is to demonstrate the example
// of Map emptyMap() of Collections

import java.util.*;

public class EmptyMap {
    public static void main(String args[]) {
        // By using emptyMap() method is 
        // to get a empty map
        Map map = Collections.emptyMap();

        // Display Empty map
        System.out.println("map: " + map);
    }
}

Output

map: {}


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.