Below is my ordinary for loop and I want to refactor the same code to use java8 IntStream.
for(int i=0; i<= historyList.size(); i++) {
if (isExist(historyList, status, i)) {
return historyList.get(i).getCreated();
}
}
And below is the refactored IntStream
version
IntStream.rangeClosed(0, historyList.size()).forEach(i -> {
if (isExist(historyList, status, i)) {
return historyList.get(i).getCreated(); -- Error: Unexpected return value
}
});
But getting error at the return as shown above.
Error: Unexpected return value
How to refactor the above code in a proper way?