How to print ArrayList from HashMap?
Map<String, ArrayList<Car>> cars = new HashMap<String, ArrayList<Car>>;
ArrayList<Car> carList = cars.get("bmw");
for (int i = 0; i < carList.size(); i++) {
System.out.println(carList.get(i));
}
The code causes:
java.lang.NullPointerException
Despite the “bmw” key exists and is populated.
Try adding in a
to check and see what exactly is in it (in the Map, and the ArrayList of cars).