Class ListUtils


  • public class ListUtils
    extends Object
    Utility methods for List conversions.
    • Method Detail

      • toList

        @NotNull
        public static <T> @NotNull List<T> toList​(@NotNull
                                                  @NotNull Iterable<? extends T> iterable)
        Convert an iterable to a list. The returning list is mutable and supports all optional operations.
        Type Parameters:
        T - the type of the elements
        Parameters:
        iterable - the iterable to convert
        Returns:
        the list
      • toLinkedList

        @NotNull
        public static <T> @NotNull List<T> toLinkedList​(Iterable<T> iterable)
        Convert an iterable to a LinkedList. The returning LinkedList is mutable and supports all optional operations.
        Type Parameters:
        T - the type of the elements
        Parameters:
        iterable - the iterator to convert
        Returns:
        the LinkedList
      • toList

        @NotNull
        public static <T> @NotNull List<T> toList​(Iterator<? extends T> iterator)
        Convert an iterator to a list. The returning list is mutable and supports all optional operations.
        Type Parameters:
        T - the type of the elements
        Parameters:
        iterator - the iterator to convert
        Returns:
        the list
      • partitionList

        @NotNull
        public static <T> @NotNull List<List<T>> partitionList​(List<T> list,
                                                               int n)
        Split a list into partitions of a given size.
        Type Parameters:
        T - the type of the elements
        Parameters:
        list - the list to partition
        n - the size of partitions
        Returns:
        a list of partitions. The resulting partitions aren’t a view of the main List, so any changes happening to the main List won’t affect the partitions.
      • reverse

        @NotNull
        public static <T> @NotNull List<T> reverse​(List<T> l)
        Returns a new list containing the elements of the specified list in reverse order.
        Type Parameters:
        T - the type of elements in the list
        Parameters:
        l - the list to be reversed, must not be null
        Returns:
        a new list containing the elements of the specified list in reverse order
        Throws:
        NullPointerException - if the list is null