I have one list List with a quite a number of fields, need to create a List in a single pass using stream.
We need to mark the field current true in the List, for the least positive integer in the input List
Input:
[PT(pn=-1, endDate=2019-01-11, dp=MAR 2019,..), PT(pn=4, endDate=null, dp=APR 2019,..), PT(pn=6, endDate=2019-05-11, dp=MAY 2019,..)]Output:
[OP(pn=11, current=false, dp=MAR 2019), OP(pn=4, current=true, dp=APR 2019), OP(pn=6, current=false, dp=MAY 2019)]
class OP{
Integer pn;
Boolean current;
String dp;
}
List<OP> filteredList11 = availablePT.get()
.stream()
.map(e->new OP(e.getPn(),**,e.getDp()))
.collect(Collectors.toList());
I am bit confused how to derive the logic to update the current flag(**) as true for the least positive integer in a single loop.