Alex Rivera | Logout

Why can Java Collections not directly store Primitives types?

Asked 2010-03-24T02:26:42.253
149

Java collections only store Objects, not primitive types; however we can store the wrapper classes.

Why this constraint?

Edit
Report

1 Answer

8

There is the concept of auto-boxing and auto-unboxing. If you attempt to store an int in a List<Integer> the Java compiler will automatically convert it to an Integer.

answered 2010-03-24T02:32:17.283

Your Answer