1final Object firstElement = list.stream()
2 .findFirst()
3 .orElse(new Object()) //Give a default value if there are no elements
4
5final Object firstElement = list.stream()
6 .findFirst()
7 .orElseThrow(() -> new Exception()) //Throw an exception if there are no elements