I am looking for an optimized solution to remove null keys from a HashMap. This HashMap is present inside an ArrayList. Please find the example below.
public class Car {
String year;
String model;
Map<String,String> colors;
}
List<Car> listOfCars = new ArrayList<Car>();
Sample of the colors map could be like this:
{
red(1),
blue(2),
green(3),
black(4),
null(5)
}
I need a solution to iterate over the listOfCars, get the map of colors and remove the null key from that. Trying to see any other options in Java8 rather than using an Iterator.
Thanks!
for (Car car : listOfCars) { car.colors.remove(null); }.