• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding primitives to Lists

 
Tony Bateman
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can wrap each integer in an Integer.
 
Tony Bateman
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic