Class Lists

java.lang.Object
panda.utilities.collection.Lists

public final class Lists extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    add(Collection<T> list, T element)
    Add element to the given collection and get added value as result
    static <T> T
    get(List<T> list, int index)
    Get element of list at the given position without risk of ArrayIndexOutOfBoundsException
    static <T> List<T>
    mutableOf(T... elements)
    Create mutable list from varargs
    static <T> List<T>
    reverse(List<T> list)
    Reverse the provided list and return its
    static <T> void
    sort(Comparator<T> comparator, List<? extends T>... collections)
    Sort similar lists using the same comparator
    static <T> List<T>[]
    split(List<T> list, T delimiter)
    Split list by the given delimiter
    static <T> List<T>
    subList(List<T> list, int startIndex)
    Returns a view of the portion of the given list
    static <T> ArrayList<T>
    subList(List<T> list, int startIndex, int endIndex)
    Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex exclusive.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • add

      public static <T> T add(Collection<T> list, T element)
      Add element to the given collection and get added value as result
      Type Parameters:
      T - type of element
      Parameters:
      list - the collection to use
      element - the element to add
      Returns:
      the element to add
    • subList

      public static <T> List<T> subList(List<T> list, int startIndex)
      Returns a view of the portion of the given list
      Type Parameters:
      T - type of list
      Parameters:
      list - the list to use
      startIndex - low endpoint (inclusive) of the subList
      Returns:
      a view of the specified range within this list
    • subList

      public static <T> ArrayList<T> subList(List<T> list, int startIndex, int endIndex)
      Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex exclusive. The returned array list is independent collection and changes does not affect the original list.
      Type Parameters:
      T - type of list
      Parameters:
      list - the list to use as source list
      startIndex - the start index
      endIndex - the end index
      Returns:
      a new list
    • sort

      @SafeVarargs public static <T> void sort(Comparator<T> comparator, List<? extends T>... collections)
      Sort similar lists using the same comparator
      Type Parameters:
      T - type of the lists
      Parameters:
      comparator - the comparator to use
      collections - the array of lists to sort
    • reverse

      public static <T> List<T> reverse(List<T> list)
      Reverse the provided list and return its
      Type Parameters:
      T - type of the list
      Parameters:
      list - the list to reverse
      Returns:
      the reversed list
    • split

      public static <T> List<T>[] split(List<T> list, T delimiter)
      Split list by the given delimiter
      Type Parameters:
      T - type of list
      Parameters:
      list - the list to split
      delimiter - the object to use as delimiter
      Returns:
      the array of lists
    • mutableOf

      @SafeVarargs public static <T> List<T> mutableOf(T... elements)
      Create mutable list from varargs
      Type Parameters:
      T - type of the list
      Parameters:
      elements - to add to the array
      Returns:
      created list
    • get

      @Nullable public static <T> T get(List<T> list, int index)
      Get element of list at the given position without risk of ArrayIndexOutOfBoundsException
      Type Parameters:
      T - type of the list
      Parameters:
      list - the list to process
      index - the index of element to get
      Returns:
      the element at the index position, null if the index is less than 0 or greater than the size of the specified list