WeakHashMap isEmpty() in Java

isEmpty(): This method is available in java.util.WeakHashMap class of Java.

Syntax:

boolean java.util.WeakHashMap.isEmpty()

This method returns true if this map contains no key-value mappings.

Parameters: NA

Returns: true if this map contains no key-value mappings.

Exceptions: NA

Approach

Java

import java.util.WeakHashMap;

public class WeakHashMapisEmpty {
    public static void main(String[] args) {

        WeakHashMap<String, String> weakHashMap =
new WeakHashMap<String, String>();

        weakHashMap.put("Java", "Program");
        weakHashMap.put("Hello", "World");

        System.out.println(weakHashMap.isEmpty());

    }
}

Output:

false


No comments:

Post a Comment