0

I'm not very used to Java streams, but basically I want to invoke different object methods after I retrieve data from the API in two different streams. I'm not sure how to do that, but here it is sort of the idea:

SimpleObject obj = new SimpleObject();

// stream1
StreamSupport
             .stream(myApi.getData())
             .map(myfunctions:function)
             // at this point I want to invoke obj.specificFunction1 and pass the result of previous map

// stream 2
StreamSupport
             .stream(myApi.getOtherData())
             .map(myfunctions:function)
             // at this point I want to invoke obj.specificFunction2 and pass the result of previous map

It would be great if those two stream could be somehow combined to make more sense. Could someone help me with this ?

Zed
  • 5,683
  • 11
  • 49
  • 81
  • https://stackoverflow.com/questions/43815221/java-8-apply-function-to-all-elements-of-stream-without-breaking-stream-chain – Sully Sep 16 '21 at 19:30
  • It depends of return result of your functions, if it's `void` than use `forEach`. If your function returns result, that should be collected- use `map` , than `collect`. – Andrei Yusupau Sep 17 '21 at 20:35

0 Answers0