WeakHashMap boolean isEmpty() method Example Program


Returns true if this map contains no key-value mappings. This result is a snapshot, and may not reflect unprocessed entries that will be removed before next attempted access because they are no longer referenced.

Program

package com.candidjava;

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

/* 
 * @author : Mohan 
 * @description : The isEmpty() method is used to return true if this map contains no key-value mappings
 */
public class WeakHashMapIsEmpty {
	public static void main(String[] args) {
		Map<String, String> weakHashMap = new WeakHashMap<String, String>();

		System.out.println("Map is empty: " + weakHashMap.isEmpty());

		System.out.println("Putting values into the Map");
		weakHashMap.put("1", "anandh");
		weakHashMap.put("2", "hari");
		weakHashMap.put("3", "vinoth");
		weakHashMap.put("4", "kamal");
		weakHashMap.put("5", "karthic");
		weakHashMap.put("6", "mohan");

		System.out.println("Map is empty: " + weakHashMap.isEmpty());
	}
}

Output

Map is empty: true
Putting values into the Map
Map is empty: false

Explanation

public boolean isEmpty()
Returns true if this map contains no key-value mappings. This result is a snapshot, and may not reflect unprocessed entries that will be removed before next attempted access because they are no longer referenced.
Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class AbstractMap<K,V>
Returns:
true if this map contains no key-value mappings


Related Post

Comments


©candidjava.com