Hey there,
I am trying to use an ArrayList to store my user-defined objects yet I keep coming up with the same problem...
When I run that code, the output is...Code:public static void main() { ArrayList list = new ArrayList(); list.add(new item("Fred", 100)); list.add(new item("Jim",200)); System.out.println(((item)(list.get(0)).getIdentity()); }
JIM
but of course is should be fred, is this a problem with referencing, it seems like the last item I add is overwriting the reference or data of the object(s) in the list. Can anyone suggest a solution or at least an explanation of the problem.
Freddy_no_nose.




Reply With Quote