Files
2022-12-23 13:26:29 +00:00

14 lines
416 B
Java

// "Collapse loop with stream 'findFirst()'" "true-preview"
import java.util.List;
class Scratch {
public void setStatus(List<MutablePair> destinations, String destination, Integer status) {
destinations.stream().filter(pair -> pair.first.compareTo(destination) == 0).findFirst().ifPresent(pair -> pair.second = status);
}
private static class MutablePair {
String first;
Integer second;
}
}