1

I need to create a map where the Integer corresponds with the maintenance periods a car has scheduled and with the set being the cars that have that amount of periods.

I'm getting these errors: Lambda expression's signature does not match the signature of the functional interface method get()

AND

The method getValue() is undefined for the type T - The method size() is undefined for the type T I'm using eclipse if thats of any help. Any help would be greatly appreciated.

private Map<Integer, Set<Auto>>  summarize(Map<String, List<Maintenance>> carMaintenanceMap) {
      //carMap is <String, Car>
        Map<Integer, Set<Car>> map = new HashMap<>() ;
        map = carMaintenanceMap.entrySet().stream()
                
                .collect(Collectors.toMap(
                        entry -> 
                        
                        entry.getValue(), val -> val.size() ,
                        
                        
                        entry -> 
                        
                        entry.getKey(), k -> this.carMap.entrySet().stream()
                         .filter(entry -> entry.getKey().equals(k)µ
                           .collect(Collectors.toSet())
                        
                        
                          ));
    }
  • Does this answer your question? [Java 8 List into Map](https://stackoverflow.com/questions/20363719/java-8-listv-into-mapk-v) – mohammedkhan Aug 27 '21 at 16:17
  • 1
    How many arguments do you think `Collectors.toMap` takes? You're passing it four, only one of which seems to be of the expected type. – Louis Wasserman Aug 27 '21 at 16:19
  • 1
    You seem to want `groupingBy`. Also, I’m not sure why you assign to a `new HashMap` and the immediately reassign. – Boris the Spider Aug 27 '21 at 16:25
  • @LouisWasserman You're right, I fixed it. Stupid of me for not realising it. Thanks! – Brent De Corte Aug 27 '21 at 16:37
  • *carMaintenanceMap* is a `List`. How is a `Car` related to `Auto`? – Thiyagu Aug 27 '21 at 16:41
  • 1
    It would be great if you can provide an example for input and output – ray Aug 27 '21 at 17:46
  • You are streaming an `entrySet()`. But you are doing `collect(Collectors.toMap(entry -> entry.getValue(), val -> val.size(), ...`. No matter what you call it, `val` is still an `entry` which has no `size()` method. – WJS Aug 27 '21 at 18:17
  • You need to provide a concrete example of data and results. Any answer given the information provided would simply be a guess (and if they got it correct, a lucky one). – WJS Aug 27 '21 at 18:24

0 Answers0