Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding primitives to Lists

 
Tony Bateman
Ranch Hand
Posts: 43
  • 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: 43
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic