10:29 pm - Monday March 27, 2017

This Program is used to get the empty map (immutable) using emptyMap() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Program is used to get the empty map (immutable) using emptyMap() method

Example Program


import java.util.*;

public class CollectionsDemo {
	public static void main(String args[]) {
		// create an empty map
		Map emptymap = Collections.emptyMap();

		System.out.println("Created empty immutable map: " + emptymap);

		// try to add elements
		emptymap.put("1", "value");
	}
}

 

Output:

Created empty immutable map: {}
Exception in thread “main” java.lang.UnsupportedOperationException

Description:

The emptyMap() method is used to get the empty map (immutable). This map is serializable

 

Declaration

public static final <K,V> Map<K,V> emptyMap()

 

Parameters:

NA

 

Return Value

NA

 

Exception

NA

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.