java.util.WeakHashMap.isEmpty() Method

Advertisements


Description

The isEmpty() method is used to return true if this map contains no key-value mappings

Declaration

Following is the declaration for java.util.WeakHashMap.isEmpty() method.

public boolean isEmpty()

Parameters

  • NA

Return Value

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

Exception

  • NA

Example

The following example shows the usage of java.util.WeakHashMap.isEmpty() method.

package com.tutorialspoint;

import java.util.Map;
import java.util.WeakHashMap;

public class WeakHashMapDemo {
   public static void main(String[] args) { 
      Map<String, String> weakHashMap = new WeakHashMap<String, String>();
      
      // check map contents
      System.out.println("Checking the map entries");
      System.out.println("Map is empty: "+weakHashMap.isEmpty());
      
      // put keys and values in the Map
      System.out.println("Putting values into the Map");
      weakHashMap.put("1", "first");
      weakHashMap.put("2", "two");
      weakHashMap.put("3", "three");
      
      // checking Map
      System.out.println("Map is empty: "+weakHashMap.isEmpty());
   }    
}

Let us compile and run the above program, this will produce the following result.

Checking the map entries
Map is empty: true
Putting values into the Map
Map is empty: false



Advertisements
Advertisements