• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrarList holds objects, not primitives...  RSS feed

 
iti garg
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
please tell me what does this statement mean...

ArrarList holds objects, not primitives.

please explian me with suitable example.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Object:


A primitive:


What the statement means is you can only put the first one in to an ArrayList. The difference would be more noticable if you tried to put a primitive into an array list pre-Java 5 (you'd get a compilation error). But now if you do this:

autoboxing will convert bar into an Integer and add that.
[ November 07, 2008: Message edited by: Paul Sturrock ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!