Map<String, Object> map = new HashMap<String, Object>()
This gives you a map with keys of type String and values โโof type Object, which basically means any descendant of type Object (Date, Integer, String, etc.). Other answers correctly indicate that instead of using primitives such as int, boolean, you need to use their analogues Integer, Boolean, etc.
The return type of the get
operation on such a map is Object
. Therefore, the developer must properly handle type information.
A good answer to the question of what is the difference between a Hashtable and a HashMap is provided here .
source share