Alex Rivera | Logout

How can I determine the type of object an ArrayList iterator will return next?

Asked 2010-01-31T23:58:20.870
9

I have an ArrayList and I am using an iterator to run through it. I need to find out what type of object is next:

Iterator vehicleIterator = vehicleArrayList.iterator();

while(vehicleIterator.hasNext())
{
     //How do I find the type of object in the arraylist at this point
     // for example, is it a car, bus etc... 
}

Thanks

Edit
Report

1 Answer

0

Generics can of great help here. You can then use instanceof to to determine Car of Bus.

answered 2010-02-01T04:36:31.473

Your Answer