Add a car to a map based on its model I have a map of cars Map&lt;String, Set&lt;Car&gt;&gt; which can be returned by getCarsMap() method where key is model of car , and value is list of cars of same model.

I would like to improve Car addCar(Car car) function. For now I wrote this a bit ugly piece of code.

public Car addCar(Car car) {
if(getCarsMap().entrySet().stream().anyMatch(es -&gt; es.getKey().equals(car.getModel()))){
    if(!getCarsMap().get(car.getModel()).contains(car)){
        getCarsMap().get(car.getModel()).add(car);
    }
}else{
    Set&lt;Car&gt; tmpSet = new HashSet&lt;Car&gt;();
    tmpList.add(car);
    getCarsMap().put(car.getModel(), tmpSet) ;
}
return car;}


Since purpose is to learn streams, lambdas etc. (java8) I would love to use as these things as much as possible.
There is not need to go to streams at all for a piece of functionality already implemented in the containsKey member function of Map.

if(getCarsMap().containsKey(car.getModel())){
    if(!getCarsMap().get(car.getModel()).contains(car)){
        getCarsMap().get(car.getModel()).add(car);
    }
}