I would like to find the most efficent way how to find 1st element of collection which is inside another collection where I take also the 1st entry. I think this is "ugly" solution.
public class UnitLine {}
public class Unit {
private Collection<UnitLine> unitLines;
public Collection<UnitLine> getUnitLines() {
return unitLines;
}
}
public class Wrapper {
Collection<Unit> units;
public Collection<Unit> getUnits() {
return units;
}
}
public static void main(String[] args) {
Wrapper wrapper = new Wrapper();
Unit unit = wrapper.getUnits().stream().findFirst().orElseGet(null);
if (unit != null) {
UnitLine unitLine = unit.getUnitLines().stream().findFirst().orElseGet(null);
if (unitLine != null) {
// do something
}
}
}