How should I change from Object value to int value?

ArrayList ap = new ArrayList();ap.add(10);I want int value...How should I do?int a22 =(int)ap.get(0);It's not working.Help me.
[176 byte] By [sednafox@nate.coma] at [2007-10-3 3:30:01]
# 1

This is tricky. Before 1.5, you could not do ap.add(10), you would have to do

ap.add(Integer.valueOf(10)); // OR

ap.add(new Integer(10));

This is called autoboxing and the compiler provides the extra code for you.

If you want to get it out as an int, you have to choices

1) Use generics

List<Integer> ap = new ArrayList<Integer>();

ap.add(10);

int ten = ap.get(0);

2) Cast

List ap = new ArrayList();

ap.add(10);

int ten = ((Integer)ap.get(0).intValue();

IanSchneidera at 2007-7-14 21:23:52 > top of Java-index,Java Essentials,Java Programming...
# 2
I think if he just changes his cast from (int) to (Integer), it should work.Again, this is 1.5.
ValentineSmitha at 2007-7-14 21:23:52 > top of Java-index,Java Essentials,Java Programming...
# 3
Good point, Valentine.Evil autoboxing.
IanSchneidera at 2007-7-14 21:23:52 > top of Java-index,Java Essentials,Java Programming...