0
public class ProductFamilyProcessUI implements Comparable {
    private String id;
    private int seqNo;
    private DepartmentUI department;
    private ProcessGroupUI processGroup;
    private ProcessUI process;
    private ProcessFlowType processFlowType;
    private Map<String, OutsourceToStatusEnum> outSourceToStatuses;
}

The ProductFamilyProcessUI is a list that I get in a request, I want to stream the outsourceToStatuses into another map of the same type.

Map<String, OutsourceToStatusEnum> outsourceToStatusEnumMap = productFamilyProcessUIList1
    .stream()
    .map(ProductFamilyProcessUI::getOutSourceToStatuses)
    .collect(Collectors.toMap());

I tried this but it expects input in Collectors.toMap().

Naman
  • 27,789
  • 26
  • 218
  • 353
Amaresh HM
  • 51
  • 7
  • 1
    tried something? [edit the question](https://stackoverflow.com/posts/67344742/edit) to update your attempt – Naman May 01 '21 at 09:33
  • Map outsourceToStatusEnumMap = productFamilyProcessUIList1.stream().map(ProductFamilyProcessUI::getOutSourceToStatuses).collect(Collectors.toMap(); I tried this but it expects an input in Collectors.toMap(). – Amaresh HM May 01 '21 at 09:35
  • replace `.map(ProductFamilyProcessUI::getOutSourceToStatuses)` with `.map(pf -> pf.getOutSourceToStatuses().entrySet().stream)` and then while collecting provide keyTransformer, value transformer from an `Map.Entry` as a source to the `toMap` API. – Naman May 01 '21 at 09:38
  • apart from the [API documentation](https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/stream/Collectors.html#toMap(java.util.function.Function,java.util.function.Function,java.util.function.BinaryOperator)), the duplicates shall help you transform your code looking at examples. – Naman May 01 '21 at 09:42
  • What is keyTransformer and value Transformer? I didn't understand. Can you please explain how to do this? – Amaresh HM May 01 '21 at 09:43
  • They are both `Function`s to map your elements from the stream to another object. The links provide good enough code to relate with examples. – Naman May 01 '21 at 09:46

0 Answers0