How to show a removed item or Array?

Hi there

I am really inexperienced in java programming.. well I need to figure out how to show something that has been removed from an ArrayList.size...

i.e

public void removeMe(int iIndex)

{

ArrayList.remove(iIndex);

}

I just need to kno how can I show the removed item? cheerz.. any help would be highly appriciated

[366 byte] By [sifatka] at [2007-10-3 6:17:53]
# 1
The remove method returns the element that was removed from the list.Oh, and it's not a static method either ...
YoGeea at 2007-7-15 1:02:38 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks for your reply..

well mate I am doing this assignment for a car dealer...so basically i have to show the list of cars which are sold..

i can add the cars by using

ArrayList.add(Car newCar)

and when I run the sell method on my Dealership class

it would remove the car from the ArrayList.size

so in the "sell" method I have something like this

ArrayList.remove(soldCar)

so my question is how can I show the car which have been recently removed from the ArrayList on a different method...

something like listSoldCars()...

cheerz

sifatka at 2007-7-15 1:02:38 > top of Java-index,Java Essentials,Java Programming...
# 3

At the time it is used, the remove method returns a reference to the object removed. So, you need to capture the value of this reference in a variable. If you then wish to later be able to list all of the removed items, you must then save these references in an additional list and then you can list the items in this new list, in order to see which items were removed from the original list. But ArrayList (and all other collections) do not retain a reference list of removed items. If they did, then essentially the item would not have been removed at all, since there is still an existing reference to it in the Collection (even if it were not in the active list).

masijade.a at 2007-7-15 1:02:38 > top of Java-index,Java Essentials,Java Programming...
# 4
Thank for your reply mate...well I am newcome rso dont ve much idea of how to get it done...So if you could give me a small example that would b real kind of you:)...but i understood your logic..thanks
sifatka at 2007-7-15 1:02:38 > top of Java-index,Java Essentials,Java Programming...
# 5

public void sellCar(Car car) {

allCars.remove(car);

soldCars.add(car);

}

There you go champ. You might want to limit the size of the other list so as to keep only 5 last sold or so.

-Kayaman-a at 2007-7-15 1:02:38 > top of Java-index,Java Essentials,Java Programming...
# 6
Thanks for the reply mate....:)...really helped a lot..
sifatka at 2007-7-15 1:02:38 > top of Java-index,Java Essentials,Java Programming...