This discussion is archived
6 Replies Latest reply: Jul 24, 2013 2:21 AM by PhHein RSS

ArrayList question - can add String but not int

797160 Newbie
Currently Being Moderated
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?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points