📌  相关文章
📜  查找列表 java 代码示例的第一个元素

📅  最后修改于: 2022-03-11 14:52:12.004000             🧑  作者: Mango

代码示例1
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