as @Nik means that only objects are stored in Map (any class in Java)
Now for your question, why an array of primitive Booleans can be saved -> this is because in Java (and many other languages) Array is Object
boolean cc[]={true, false}; System.out.println(cc instanceof Object);
Note β this is true only because cc has an actual array in it, but if you put zero in it β it will no longer be an instance of Object like this:
cc=null; System.out.println(cc instanceof Object);
Note 2 -> for your subtext: you cannot use them directly. Consider this example:
HashMap aMap=new HashMap(); int x=120;//int value of 120 aMap.put("120",x);//parsed Integer with value of 120 x=aMap.get("120");//compiler error - Type mismatch
One more thing, since you are interesting in this topic. I would suggest you a book called "Effective Java" by Joshua Bloch, who, by the way, developed the Java Collections, and Map is, of course, a collection.
source share