Check out example codes for "find first element of list java". It will help you in understanding the concepts better.

Code Example 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

Code Example 2

ArrayList<Type> array = new ArrayList<Type>();
System.out.printLn(array[0]);

Learn ReactJs, React Native from akashmittal.com