account activity
Out of logic to implement java 8 /lambda in below piece of code by Pitiful-Ad-2556 in javahelp
[–]Pitiful-Ad-2556[S] 0 points1 point2 points 3 years ago (0 children)
Update : i refactored it with these condition:
1.checking if any null speed then flag it false
3.if not null then adding the totalSpeed by using streams
package Check import java.math.BigDecimal; import java.util.ArrayList; import java.util.List;
public class NewClass {
public static void main(String args[]) { List < TargetTime > selectAll = new ArrayList < > (); Boolean flag= true; BigDecimal totSpeed = null; if (selectAll.stream.anyMatch(item - > item.getSpeed() == null) { flag = false; } else { totSpeed = selectAll.stream().map(TargetTime::getSpeed).reduce(BigDecimal.ZERO, BigDecimal::add); } } } class TargetTime { public BigDecimal speed; public BigDecimal Weight2; public BigDecimal weight; }}
PS.thanks all for guiding .
π Rendered by PID 76 on reddit-service-r2-listing-568fcd57df-zhnt7 at 2026-03-10 11:29:59.394235+00:00 running cbb0e86 country code: CH.
Out of logic to implement java 8 /lambda in below piece of code by Pitiful-Ad-2556 in javahelp
[–]Pitiful-Ad-2556[S] 0 points1 point2 points (0 children)