Collections static final Map emptyMap() method Example Program


Returns the empty map (immutable)

Program

package com.candidjava;

import java.util.*;

/**
 * 
 * @author karthikeyan.T
 * @description The following example shows the usage of Collections.emptyMap()
 */
public class EmptyMap {

	public static void main(String args[]) {
		Map emptymap = Collections.emptyMap();
		System.out.println("Created empty immutable map: " + emptymap);
	}
}

Output

Created empty immutable map: {}

Explanation

public static final <K,V> Map<K,V> emptyMap()
Returns the empty map (immutable). This map is serializable.
This example illustrates the type-safe way to obtain an empty set:

     Map<String, Date> s = Collections.emptyMap();
 
Implementation note: Implementations of this method need not create a separate Map object for each call. Using this method is likely to have comparable cost to using the like-named field. (Unlike this method, the field does not provide type safety.)
Since:
1.5
See Also:
EMPTY_MAP


Related Post

Comments


©candidjava.com