Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Adding primitives to Lists Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding primitives to Lists" Watch "Adding primitives to Lists" New topic
Author

Adding primitives to Lists

Tony Bateman
Ranch Hand

Joined: Mar 21, 2005
Posts: 43
Hi,

I want to create a list of integers as an ArrayList but I cannot because ArrayLists method add(Object o) expects an object and not a primitive.

How can I create simple, extensible arrays of integers?

Kind regards,

Tony.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can wrap each integer in an Integer.
Tony Bateman
Ranch Hand

Joined: Mar 21, 2005
Posts: 43
Hi,

Thanks for that; found it in "Sun Certified Programmer and Developer for Java 2" page 376.

Think I'll read the book to the end before posting again...

Cheers,

Tony.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Adding primitives to Lists
 
It's not a secret anymore!