Object obj = null; while (it.hasnext()) { obj = (Vehicle ) it.next(); if (obj instanceof Truck auxVehicle = (Truck)obj; if (obj instanceof car) auxVehicle = (car)obj; }