*
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
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: 38
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: 38
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding primitives to Lists
 
Similar Threads
random password generation
WL Proxy converting Java objects to primitives.
is it a Object?
sorting backwards with Arrays.sort()
Wrapper Class