Class CollectionUtils

java.lang.Object
io.github.amanzat.util.CollectionUtils

public final class CollectionUtils extends Object
Miscellaneous collections related utilities.
  • Constructor Details

    • CollectionUtils

      public CollectionUtils()
  • Method Details

    • getFirst

      public static <E> Optional<E> getFirst(List<E> list)
      Returns an optional containing the first element of the list if any.
      Type Parameters:
      E - The list elements type.
      Parameters:
      list - The list
      Returns:
      An optional containing the first element of the list if any
      Implementation Note:
      The optional will be empty if the list is empty or if the fist element is null.
    • isEmpty

      public static boolean isEmpty(Collection<?> collection)
      Returns true if the specified collection is empty, false otherwise.
      Parameters:
      collection - The collection to check
      Returns:
      true if the specified collection is empty, false otherwise.
      Implementation Note:
      A null collection is considered empty.
    • chunkify

      public static <T> Stream<List<T>> chunkify(Iterator<T> iterator, int size)
      Transforms an iterator into a stream of lists with a maximum size.
      Type Parameters:
      T - The element type.
      Parameters:
      iterator - The iterator
      size - The list (chunk) max size
      Returns:
      A stream of lists with the specified maximum size.
      See Also: