Possible Duplicate:
Storing primitive values in a Java collection?
ArrayList accepts only reference types as its element, not primitive datatypes.
When trying to do so it produces a compile time error.
What is the concept behind this? It seems like a limitation, is it not?
All collection classes of java store memory location of the objects they collect. The primitive values do not fit in to the same definition.
To circumvent this problem, JDK5 and onwards have autoboxing – wherein the primitives are converted to appropriate objects and back when they are added or read from the collections. Refer to the official JDK tutorial on this topic.
Checking the JDK5 source code for ArrayList helps better understanding: creating an
ArrayList<E>includes casting anObject[]array toE[].