When you put primitives in a Map in Java, they get Auto-Boxed in their object form. For example, if you have a Map , which is defined as:
Map<Integer, String> myMap = new HashMap<Integer, String>();
then you can use int primitives, as they will be automatically placed in Integer .
Regarding your initial question defining Map as such:
// using Integer for key type, can be something else Map<Integer, Object> myMap = new HashMap<Integer, Object>();
then you can place any Java object on the map.
Nico huysamen
source share