Q:

EnumMap & streams

Hi tried to figure out how to map to a EnumMap without success.  
At the moment I'm doing it in 2 steps, I create the map and then I make it a EnumMap.  
Question are. 

Is it possible to do it in only one step? 
From efficiency perspective would be better to get Values from
input, make them a set and then stream it, or just using  toMap as
its right now is correct.  thanks
Map<CarModel, CarBrand> input...  
final Map<CarBrand, CarsSellers> ret = input.values()
            .stream().filter(brand -> ! brand.equals(CarBrand. BMW))
            .collect(toMap(Function.identity(), brand -> new CarsSellers(immutableCars, this.carsDb.export(brand))));

 final EnumMap<CarBrand, CarsSellers> enumMap = new EnumMap<>(CarBrand.class);
    enumMap.putAll(ret);

A:

TL;DR: You need to use the other toMap method. 
By default a toMap uses HashMap::new as the Supplier<Map> - you need to supply a new EnumMap instead. 
final Map<CarBrand, CarsSellers> ret = input.values()
        .stream()
        .filter(brand -> brand ! = CarBrand. BMW)
        .collect(toMap(
                identity(),
                brand -> new CarsSellers(immutableCars, this.carsDb.export(brand)),
                (l, r) -> {
                    throw new IllegalArgumentException("Duplicate keys " + l + "and " + r + "."); 
                },
                () -> new EnumMap<>(CarBrand.class)));

Arguments are: 

the key extractor
the value extractor
a "mergeFunction" that takes two values, one that already exists in the Map and one to be added.  In this case, we simply throw an IllegalArgumentException as keys should be unique
the "map supplier" - this returns a new EnumMap. 

Notes on your code:

program to the interface - Map not EnumMap
enum is singleton, so you can use a ! = Enum. VALUE
an import static for Function.identity() makes things less verbose

