Java EnumMap put() methodThe put() method of Java EnumMap class is used to associate the given value with the given key in this EnumMap. SyntaxParameterskey - the key with which the given value is to be associated value - the value to be associated with the given key ReturnsThis method returns the old value associated with the specified key.
ExceptionNullPointerException - if the specified key is null. Example 1Output: Map: {Java=1, Python=2, PHP=3, Android=4} Updated Map: {Java=20, Python=2, PHP=3, Android=4, Javascript=5} First update returns: null Second update returns: 1 Example 2Output: Map: {January=1, February=2, March=3, April=4} Updated Map: {January=1, February=2, March=15, April=4, May=5} First update returns: null Second update returns: 3 Example 3Output: Map: {Monday=1, Tuesday=2, Wednesday=3} Exception in thread "main" java.lang.NullPointerException at java.util.EnumMap.typeCheck(Unknown Source) at java.util.EnumMap.put(Unknown Source) at EnumMapPutExample3.main(EnumMapPutExample3.java:18) Next TopicJava-enummap-remove-method |
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