java.lang.Object
dk.cloudcreate.essentials.shared.collections.Lists

public final class Lists extends Object
List utility methods
  • Constructor Details

    • Lists

      public Lists()
  • Method Details

    • toIndexedStream

      public static <T> Stream<Pair<Integer,T>> toIndexedStream(List<T> list)
      Convert the list to an 0-based Indexed Stream consisting of Pair's, where each Pair consists of the 0-based Index (i.e. the first index has value 0) and the corresponding List element at the given index: Pair<Index, List-element-at-the-given-index>

      Example:
      List.of("A", "B", "C") will return a Stream of:
      • Pair(0, "A")
      • Pair(1, "B")
      • Pair(2, "C")
      Type Parameters:
      T - the type of list element
      Parameters:
      list - the list that's converted to an indexed stream
      Returns:
      the indexed list
    • first

      public static <T> Optional<T> first(List<T> list)
      Get the first element in a list
      Type Parameters:
      T - the type of elements in the list
      Parameters:
      list - the non-null list
      Returns:
      the first element wrapped in an Optional or Optional.empty() if the list is empty
    • last

      public static <T> Optional<T> last(List<T> list)
      Get the last element in a list
      Type Parameters:
      T - the type of elements in the list
      Parameters:
      list - the non-null list
      Returns:
      the last element wrapped in an Optional or Optional.empty() if the list is empty
    • nullSafeList

      public static <T> List<T> nullSafeList(List<T> list)