java 8 stream api how to access previously transform object in a series of transformation

Rah*_*ase 0 java java-stream

I am iterating over a series of list items. Items is having a property id and internal id. for each item I am creating a some operation which returns another object say BackendItem along with unique id. My goal is create a map of item id and BackendItem id.

items.steam()
.filter(item -> item.type ==1)
.map(item -> backendService.createBackendItem(item))
.map (backendItem -> backendItem.id)
Run Code Online (Sandbox Code Playgroud)

here i want to create a map of (item.id,backendItem.id) Which operator should i use ?

And*_*eas 5

不要使用map(...)

items.stream()
     .filter(item -> item.type == 1)
     .collect(Collectors.toMap(item -> item.id,
                               item -> backendSerivce.createBackendItem(item).id));
Run Code Online (Sandbox Code Playgroud)