📅  最后修改于: 2022-03-11 14:52:12.004000             🧑  作者: Mango
final Object firstElement = list.stream()
.findFirst()
.orElse(new Object()) //Give a default value if there are no elements
final Object firstElement = list.stream()
.findFirst()
.orElseThrow(() -> new Exception()) //Throw an exception if there are no elements