Class ListUtils

java.lang.Object
dev.prozilla.pine.common.util.ListUtils

public final class ListUtils extends Object
Utility methods related to lists.

Some methods only work for lists, others work for all instances of a super class of List, like Collection or even Iterable. They are grouped together here for convenience.

  • Method Details

    • createSingleton

      public static <E> List<E> createSingleton(E element)
    • getInstance

      public static <E, T extends E> T getInstance(Collection<E> list, Class<T> type)
      Finds the first element in a list of a given type.

      This method is not suitable for frequent usage or usage with large lists.

      Type Parameters:
      E - The type of elements in the list
      T - The type of element to search for
      Parameters:
      list - The list to search in
      type - The type to search for
      Returns:
      The element of the given type, or null if there is none.
    • getFirst

      public static <E> E getFirst(List<E> list)
      Returns the first element in a list, or null if the list is empty.
      Type Parameters:
      E - The type of elements in the list
      Parameters:
      list - The list
      Returns:
      The first element or null.
    • find

      public static <E> E find(Iterable<E> list, Predicate<E> predicate)
      Finds the first element in a list that matches a predicate.
      Type Parameters:
      E - The type of elements in the list
      Parameters:
      list - The list
      predicate - The predicate the element must match
      Returns:
      The first element that matches the predicate, or null if there was none.