Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ArrayList question - can add String but not int

797160Jan 19 2011 — edited Jul 24 2013
I"m a little confused on something with ArrayLists. I'm trying to add an int to the ArrayList
Suppose I have:

int myInt = +<some value>+
String myString = +<some value>+
ArrayList myAL= new ArrayList(0);
myAL.add(myInt);
myAL.add(myString);

However, when I compile (using java 1.4.2), I get a compile error for the method add when it's passed an int, so I have to do this instead:

myAL.add(Integer.toString(myInt));

Is there some way I can store these integer value in my ArrayList as int's without converting them to String?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2013
Added on Jan 19 2011
6 comments
703 views