I'm in the process of learning streams. I have a conventional for loop which I would like to convert to stream.
Map<String, String> myMap = new HashMap<>();
for (Response response : responses) {
if (!myMap.isEmpty()) {
return myMap;
}
// some code related to response object
if(some condition){
myMap.put(key, value);
}
//key and value is not property of response and coming from another object
}//end for
This is just pseudo code and there is more to it than shown. I'm struggling to return the map as shown above from the stream which is also my return type of method the code resides in. How do we achieve this?