Now lets look at the list containing integer objects :
integerlist .add(new Integer(777));
In this case if we try to add String to the integerlist , it will throw a syntax error.
// integerlist .add("I am a string ");
But at the same time if we try to add null then it is valid.
If we create collection from the objects of Class O then we can add the object of the class which extend the Class O to the collection.
For example :
Here both Integer and Float are subclasses of Number therefore it is valid to add those objects to the array list.
Similarly we can add the type specific objects to the HashMap as follows :
In the above example we can see that we have added float and integer values in Number specific map.