6th December 2020
Map.of throws UnsupportedOperationException
Error When creating a new Map in Java using the Map.of operation, the exception UnsupportedOperationException is thrown when performing the remove() operation. Reason The Map.of function returns an immutable map, therefore the remove() operation is not allowed. Solution The solution is to use aHashMap, which is a mutable object, through either: or the traditional way: