#java methods

1 messages · Page 1 of 1 (latest)

simple bison
#

I am trying to use a more simple code rather than the one i have got rn.

coral cragBOT
#

<@&987246399047479336> please have a look, thanks.

simple bison
#

public void listShipmentsForClient(Client client) {
System.out.println("\nShipments for Client ID: " + client.getId());
shipments.stream()
.filter(s -> s.getShipper().equals(client))
.forEach(System.out::println);
}

cinder terrace
#

In which sense?

simple bison
#

taking out stream

cinder terrace
#

You could do a for each, with an if, and add it to a second list, but that seems more cumbersome.

simple bison
#

ohhh

sacred falcon
#

yeah it cant get much "simpler" in terms of amount of code but it is probably more efficient to java for (var shipment : shipments) { if (shipment.getShipper().equals(client)) { System.out.println(shipment); } }

coral cragBOT
cinder terrace
#

I prefer a stream to be honest, it's a more logical sequence of actions.