Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

find first element of list java

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  
 
PREVIOUS NEXT
Tagged: #find #element #list #java
ADD COMMENT
Topic
Name
1+2 =