You haven't shown your Car
type, but assuming you'd want the price of the first car, you could use:
public static void processCars(ArrayList<Car> cars) {
Car car = cars.get(0);
System.out.println(car.getPrice());
}
Note that I've changed the name of the list from car
to cars
- this is a list of cars, not a single car. (I've changed the method name in a similar way.)
If you only want the method to process a single car, you should change the parameter to be of type Car
:
public static void processCar(Car car)
and then call it like this:
// In the main method
processCar(cars.get(0));
If you do leave it as processing the whole list, it would be worth generalizing the parameter to List<Car>
- it's unlikely that you'll really require that it's an ArrayList<Car>
.