Java Collections emptyMap() MethodThe emptyMap() method of Java Collections class returns an empty map which is immutable. SyntaxFollowing is the declaration of emptyMap() method: ParameterThis method does not accept any parameter. ReturnsThe emptyMap() method returns an empty immutable Map. ExceptionsNA Compatibility VersionJava 1.5 and above Example 1Test it NowOutput: Created Empty Map: {} Example 2Test it NowOutput: Created Empty Map: {} Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.AbstractMap.put(AbstractMap.java:209) at myPackage.CollectionsEmptyMapExample2.main(CollectionsEmptyMapExample2.java:9) Example 3Test it NowOutput: Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.AbstractMap.put(AbstractMap.java:209) at myPackage.CollectionsEmptyMapExample3.main(CollectionsEmptyMapExample3.java:7) Next TopicJava Collections Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India