Package: java.util

## [Java] Interface List

-     public interface List

  GDK enhancements for List.

  displayName:
    List
  receiverFqcn:
    java.util.List

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `<T>` | `public boolean` | `addAll(int index, T[] items)` Modifies this list by inserting all the elements in the specified array into the list at the specified position.
    `<T>` | `public List<T>` | `asChecked(Class<T> type)` Creates a checked view of a List.
    `<T>` | `public List<T>` | `asImmutable()` A convenience method for creating an immutable List.
    `<T>` | `public List<T>` | `asReversed()` Creates a view list with reversed order, and the order of original list will not change.
    `<T>` | `public List<T>` | `asSynchronized()` Creates a synchronized view of a List.
    `<T>` | `public List<T>` | `asUnmodifiable()` Creates an unmodifiable view of a List.
    `<T>` | `public BufferedIterator<T>` | `bufferedIterator()` Returns a `BufferedIterator` that allows examining the next element without consuming it.
    `<T>` | `public List<T>` | `drop(int num)` Drops the given number of elements from the head of this List.
    `<T>` | `public List<T>` | `dropRight(int num)` Drops the given number of elements from the tail of this List.
    `<T>` | `public List<T>` | `dropWhile(Closure condition)` Returns a suffix of this List where elements are dropped from the front while the given Closure evaluates to true.
    `<T>` | `public List<T>` | `dropWhile(Predicate<? super T> condition)` Returns a suffix of a List where elements are dropped from the front while the predicate is satisfied.
    `<T>` | `public List<T>` | `each(Closure closure)` Iterates through a List, passing each item to the given closure.
    `<T>` | `public List<T>` | `eachWithIndex(Closure closure)` Iterates through a List, passing each item and the item's index (a counter starting at zero) to the given closure.
    `` | `public boolean` | `equals(Object[] right)` Determines if the contents of this list are equal to the contents of the given array in the same order.
    `` | `public boolean` | `equals(List right)` Compare the contents of two Lists.
    `` | `public Process` | `execute()` Executes the command specified by the given list.
    `` | `public Process` | `execute(String[] envp, File dir)` Executes the command specified by the given list, with the environment defined by `envp` and under the working directory `dir`.
    `` | `public Process` | `execute(List envp, File dir)` Executes the command specified by the given list, with the environment defined by `envp` and under the working directory `dir`.
    `` | `public Process` | `execute(Map<String, Object> options)` Executes the command specified by the given list with options provided as named parameters.
    `<T>` | `public List<T>` | `findAll(Closure closure)` Finds all values matching the closure condition.
    `<T>` | `public List<T>` | `findAll()` Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).
    `<T>` | `public T` | `first()` Returns the first item from the List.
    `<T, E>` | `public List<T>` | `flatten()` Flatten a List.
    `<T>` | `public List<T>` | `getAt(Range range)` Support the range subscript operator for a List.
    `<T>` | `public List<T>` | `getAt(EmptyRange range)` Support the range subscript operator for a List.
    `<T>` | `public List<T>` | `getAt(Collection indices)` Select a List of items from a List using a Collection to identify the indices to be selected.
    `<T>` | `public T` | `getAt(int idx)` Support the subscript operator for a List.
    `<T>` | `public T` | `getAt(Number idx)` Support subscript operator for list access.
    `<T>` | `public List<T>` | `grep(Object filter)` Iterates over the collection of items and returns each item that matches the given filter - calling the `Object.isCase` method used by switch statements.
    `<T>` | `public List<T>` | `grep()` Iterates over the collection returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.
    `<T>` | `public T` | `head()` Returns the first item from the List.
    `<T>` | `public List<T>` | `init()` Returns the items from the List excluding the last item.
    `<T>` | `public List<T>` | `intersect(Iterable<T> right)` Create a List composed of the intersection of a List and an Iterable.
    `<T>` | `public List<T>` | `intersect(Iterable<T> right, Comparator<? super T> comparator)` Create a List composed of the intersection of a List and an Iterable.
    `<T>` | `public T` | `last()` Returns the last item from the List.
    `<T>` | `public List<T>` | `leftShift(T value)` Overloads the left shift operator to provide an easy way to append objects to a List.
    `<T>` | `public List<T>` | `minus(Collection<?> removeMe)` Create a List composed of the elements of the given List minus every occurrence of elements of the given Collection.
    `<T>` | `public List<T>` | `minus(Iterable<?> removeMe)` Create a new List composed of the elements of the first List minus every occurrence of elements of the given Iterable.
    `<T>` | `public List<T>` | `minus(Object removeMe)` Create a new List composed of the elements of the first List minus every occurrence of the given element to remove.
    `<T>` | `public List<T>` | `multiply(Number factor)` Create a List composed of the elements of this Iterable, repeated a certain number of times.
    `<T>` | `public int` | `partitionPoint(IntRange range, Predicate<? super T> condition)` Returns the index of the partition point according to the given predicate (the index of the first element of the second partition).
    `<T>` | `public int` | `partitionPoint(Predicate<? super T> condition)` Returns the index of the partition point according to the given predicate (the index of the first element of the second partition).
    `` | `public List<Process>` | `pipeline()` Creates a native OS pipeline from a list of commands, using ProcessBuilder.startPipeline.
    `<T>` | `public List<T>` | `plus(Iterable<T> right)` Create a List as a union of a List and an Iterable.
    `<T>` | `public List<T>` | `plus(Collection<T> right)` Create a List as a union of a List and a Collection.
    `<T>` | `public List<T>` | `plus(int index, T[] items)` Creates a new List by inserting all the elements in the specified array to the elements from the original List at the specified index.
    `<T>` | `public List<T>` | `plus(int index, List<T> additions)` Creates a new List by inserting all the elements in the given additions List to the elements from the original List at the specified index.
    `<T>` | `public List<T>` | `plus(int index, Iterable<T> additions)` Creates a new List by inserting all the elements in the given Iterable to the elements from this List at the specified index.
    `<T>` | `public List<T>` | `plus(T right)` Create a List as a union of a List and an Object.
    `<T>` | `public T` | `pop()` Removes the initial item from the List.
    `<T>` | `public boolean` | `push(T value)` Prepends an item to the start of the List.
    `<T>` | `public void` | `putAt(int idx, T value)` A helper method to allow lists to work with subscript operators.
    `<T>` | `public void` | `putAt(Number idx, T value)` Support subscript operator for list modification.
    `` | `public void` | `putAt(EmptyRange range, Object value)` A helper method to allow lists to work with subscript operators.
    `` | `public void` | `putAt(EmptyRange range, Collection value)` A helper method to allow lists to work with subscript operators.
    `` | `public void` | `putAt(IntRange range, Collection col)` List subscript assignment operator when given a range as the index and the assignment operand is a collection.
    `` | `public void` | `putAt(IntRange range, Object value)` List subscript assignment operator when given a range as the index.
    `` | `public void` | `putAt(List splice, Collection values)` A helper method to allow lists to work with subscript operators.
    `` | `public void` | `putAt(List splice, Object value)` A helper method to allow lists to work with subscript operators.
    `<E>` | `public E` | `removeAt(int index)` Modifies this list by removing the element at the specified position in this list.
    `<T>` | `public T` | `removeLast()` Removes the last item from the List.
    `<T>` | `public List<T>` | `reverse()` Creates a new List with the identical contents to this list but in reverse order.
    `<T>` | `public List<T>` | `reverse(boolean mutate)` Reverses the elements in a list.
    `<T>` | `public List<T>` | `reverseEach(Closure closure)` Iterate over each element of the list in the reverse order.
    `` | `public void` | `shuffle()` Randomly reorders the elements of the specified list.
    `` | `public void` | `shuffle(Random rnd)` Randomly reorders the elements of the specified list using the specified random instance as the source of randomness.
    `<T>` | `public List<T>` | `shuffled()` Creates a new list containing the elements of the specified list but in a random order.
    `<T>` | `public List<T>` | `shuffled(Random rnd)` Creates a new list containing the elements of the specified list but in a random order using the specified random instance as the source of randomness.
    `<T>` | `public List<T>` | `sort(IntRange range, boolean mutate, Comparator<? super T> comparator)` Sorts the Iterable using the given Comparator over the given index range.
    `<T>` | `public List<T>` | `sort(IntRange range, Comparator<? super T> comparator)` Sorts the Iterable using the given Comparator over the given index range.
    `<T>` | `public List<T>` | `sort(IntRange range, boolean mutate, Closure<?> closure)` Sorts elements in the given index range using the given Closure to determine the ordering.
    `<T>` | `public List<T>` | `sort(IntRange range, Closure<?> closure)` A sort variant that takes an index range and always mutates the original list.
    `<T>` | `public List<T>` | `sort(IntRange range)` A mutating sort variant that takes an index range.
    `<T>` | `public List<List<T>>` | `split(Closure closure)` Splits all items into two collections based on the closure condition.
    `<T>` | `public List<List<T>>` | `split(Predicate<? super T> predicate)` Splits all items into two lists based on the predicate.
    `<T>` | `public List<T>` | `subList(IntRange range)` Returns a view of the portion of this list given by the specified range.
    `<T>` | `public Set<List<T>>` | `subsequences()` Finds all non-null subsequences of a list.
    `<T>` | `public List<T>` | `swap(int i, int j)` Swaps two elements at the specified positions.
    `<T>` | `public List<T>` | `tail()` Returns the items from the List excluding the first item.
    `<T>` | `public List<T>` | `take(int num)` Returns the first `num` elements from the head of this List.
    `<T>` | `public List<T>` | `takeRight(int num)` Returns the last `num` elements from the tail of this List.
    `<T>` | `public List<T>` | `takeWhile(Closure condition)` Returns the longest prefix of this list where each element passed to the given closure condition evaluates to true.
    `<T>` | `public List<T>` | `takeWhile(Predicate<? super T> condition)` Returns the longest prefix of a List where each element passes the given predicate.
    `` | `public ProcessBuilder` | `toProcessBuilder()` Creates a ProcessBuilder from a command list.
    `<T>` | `public List<T>` | `toSorted(IntRange range, Closure<?> closure)` A sort variant that takes an index range and never modifies the original list.
    `<T>` | `public List<T>` | `toSorted(IntRange range, Comparator<? super T> comparator)` Returns a list, sorted over the given range using a NumberAwareComparator, leaving the original list unmodified.
    `<T>` | `public List<T>` | `toSorted(IntRange range)` Returns a list, sorted over the given range using a NumberAwareComparator, leaving the original list unmodified.
    `` | `public SpreadMap` | `toSpreadMap()` Creates a spreadable map from this list.
    `<T>` | `public List<T>` | `toUnique(Comparator<? super T> comparator)` Returns a List containing the items from the List but with duplicates removed.
    `<T>` | `public List<T>` | `toUnique()` Returns a List containing the items from the List but with duplicates removed using the natural ordering of the items to determine uniqueness.
    `<T>` | `public List<T>` | `toUnique(Closure condition)` Returns a List containing the items from the List but with duplicates removed.
    `` | `public List` | `transpose()` Adds GroovyCollections#transpose(List) as a method on lists.
    `<T>` | `public List<T>` | `union(Iterable<T> right)` Create a List composed of the union of a List and an Iterable.
    `<T>` | `public List<T>` | `union(Iterable<T> right, Comparator<? super T> comparator)` Create a List composed of the union of a List and an Iterable.
    `<T>` | `public List<T>` | `unique()` Modifies this List to remove all duplicated items, using Groovy's default number-aware comparator.
    `<T>` | `public List<T>` | `unique(boolean mutate)` Remove all duplicates from a given List using Groovy's default number-aware comparator.
    `<T>` | `public List<T>` | `unique(Closure closure)` A convenience method for making a List unique using a Closure to determine duplicate (equal) items.
    `<T>` | `public List<T>` | `unique(boolean mutate, Closure closure)` A convenience method for making a List unique using a Closure to determine duplicate (equal) items.
    `<T>` | `public List<T>` | `unique(Comparator<? super T> comparator)` Remove all duplicates from a given List.
    `<T>` | `public List<T>` | `unique(boolean mutate, Comparator<? super T> comparator)` Remove all duplicates from a given List.
    `<T>` | `public ListWithDefault<T>` | `withDefault(Closure<T> init)` An alias for `withLazyDefault` which decorates a list allowing it to grow when called with index values outside the normal list bounds.
    `<T>` | `public ListWithDefault<T>` | `withEagerDefault(Closure<T> init)` Decorates a list allowing it to grow when called with a non-existent index value.
    `<T>` | `public ListWithDefault<T>` | `withLazyDefault(Closure<T> init)` Decorates a list allowing it to grow when called with a non-existent index value.

- - ### Method Detail

    - #### <T> public boolean addAll(int index, T[] items)

      Modifies this list by inserting all the elements in the specified array into the list at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they occur in the array. The behavior of this operation is undefined if the specified array is modified while the operation is in progress. See also `plus` for similar functionality with copy semantics, i.e. which produces a new list after adding the additional items at the specified position but leaves the original list unchanged.

      Parameters:
        `items` - array containing elements to be added to this collection
        `index` - index at which to insert the first element from the specified array
      Returns:
        `true` if this collection changed as a result of the call
      See Also:
        List.addAll
      Since:
        1.7.2

    - #### <T> public List<T> asChecked(Class<T> type)

      Creates a checked view of a List.

      See Also:
        Collections.checkedList
      Since:
        5.0.0

    - #### <T> public List<T> asImmutable()

      A convenience method for creating an immutable List.

           def mutable = [1,2,3]
           def immutable = mutable.asImmutable()
           try {
               immutable << 4
               assert false
           } catch (UnsupportedOperationException) {
               assert true
           }
           mutable << 4
           assert mutable.size() == 4
           assert immutable.size() == 3

      Returns:
        an unmodifiable view of a copy of the original, i.e. an effectively immutable copy
      See Also:
        asUnmodifiable(java.util.List)
      Since:
        1.0

    - #### <T> public List<T> asReversed()

      Creates a view list with reversed order, and the order of original list will not change.

           def list = ["a", 6, true]
           assert list.asReversed() == [true, 6, "a"]
           assert list == ["a", 6, true]

      Type Parameters:
        `T` - the type of element
      Returns:
        the reversed list
      Since:
        4.0.0

    - #### <T> public List<T> asSynchronized()

      Creates a synchronized view of a List.

      Returns:
        a synchronized List
      See Also:
        Collections.synchronizedList
      Since:
        1.0

    - #### <T> public List<T> asUnmodifiable()

      Creates an unmodifiable view of a List.

           def mutable = [1,2,3]
           def unmodifiable = mutable.asUnmodifiable()
           try {
               unmodifiable << 4
               assert false
           } catch (UnsupportedOperationException) {
               assert true
           }
           mutable << 4
           assert unmodifiable.size() == 4

      Returns:
        an unmodifiable view of the List
      See Also:
        Collections.unmodifiableList
      Since:
        2.5.0

    - #### <T> public BufferedIterator<T> bufferedIterator()

      Returns a `BufferedIterator` that allows examining the next element without consuming it.

           assert [1, 2, 3, 4].bufferedIterator().with { [head(), toList()] } == [1, [1, 2, 3, 4]]

      Returns:
        a BufferedIterator for traversing self
      Since:
        2.5.0

    - #### <T> public List<T> drop(int num)

      Drops the given number of elements from the head of this List.

           def strings = [ 'a', 'b', 'c' ]
           assert strings.drop( 0 ) == [ 'a', 'b', 'c' ]
           assert strings.drop( 2 ) == [ 'c' ]
           assert strings.drop( 5 ) == []

      Parameters:
        `num` - the number of elements to drop from this Iterable
      Returns:
        a List consisting of all the elements of this Iterable minus the first `num` elements, or an empty list if it has less than `num` elements.
      Since:
        1.8.1

    - #### <T> public List<T> dropRight(int num)

      Drops the given number of elements from the tail of this List.

           def strings = [ 'a', 'b', 'c' ]
           assert strings.dropRight( 0 ) == [ 'a', 'b', 'c' ]
           assert strings.dropRight( 2 ) == [ 'a' ]
           assert strings.dropRight( 5 ) == []

      Parameters:
        `num` - the number of elements to drop from this List
      Returns:
        a List consisting of all the elements of this List minus the last `num` elements, or an empty List if it has less than `num` elements.
      Since:
        2.4.0

    - #### <T> public List<T> dropWhile(Closure condition)

      Returns a suffix of this List where elements are dropped from the front while the given Closure evaluates to true. Similar to Iterable#dropWhile(groovy.lang.Closure) except that it attempts to preserve the type of the original list.

           def nums = [ 1, 3, 2 ]
           assert nums.dropWhile{ it < 4 } == []
           assert nums.dropWhile{ it < 3 } == [ 3, 2 ]
           assert nums.dropWhile{ it != 2 } == [ 2 ]
           assert nums.dropWhile{ it == 0 } == [ 1, 3, 2 ]

      Parameters:
        `condition` - the closure that must evaluate to true to continue dropping elements
      Returns:
        the shortest suffix of the given List such that the given closure condition evaluates to true for each element dropped from the front of the List
      Since:
        1.8.7

    - #### <T> public List<T> dropWhile(Predicate<? super T> condition)

      Returns a suffix of a List where elements are dropped from the front while the predicate is satisfied. A "fat-free" variant of List.dropWhile accepting a Predicate.

           assert [1, 2, 3, 0, 4].dropWhile(n -> n < 3) == [3, 0, 4]

      Parameters:
        `condition` - the predicate that must evaluate to true to continue dropping elements
      Returns:
        the shortest suffix of the given List such that its first element does not pass the given predicate
      Since:
        6.0.0

    - #### <T> public List<T> each(Closure closure)

      Iterates through a List, passing each item to the given closure.

      Parameters:
        `closure` - the closure applied on each element found
      Returns:
        the self List
      Since:
        2.4.0

    - #### <T> public List<T> eachWithIndex(Closure closure)

      Iterates through a List, passing each item and the item's index (a counter starting at zero) to the given closure.

      Parameters:
        `closure` - a Closure to operate on each item
      Returns:
        the self List
      Since:
        2.4.0

    - #### public boolean equals(Object[] right)

      Determines if the contents of this list are equal to the contents of the given array in the same order. This returns `false` if either collection is `null`.

          assert [1, "a"].equals( [ 1, "a" ] as Object[] )

      Parameters:
        `right` - the Object[] being compared to
      Returns:
        true if the contents of both collections are equal
      Since:
        1.5.0

    - #### public boolean equals(List right)

      Compare the contents of two Lists. Order matters. If numbers exist in the Lists, then they are compared as numbers, for example 2 == 2L. If both lists are `null`, the result is true; otherwise if either list is `null`, the result is `false`.

          assert ["a", 2].equals(["a", 2])
           assert ![2, "a"].equals("a", 2)
           assert [2.0, "a"].equals(2L, "a") // number comparison at work

      Parameters:
        `right` - the List being compared to
      Returns:
        boolean `true` if the contents of both lists are identical, `false` otherwise.
      Since:
        1.0

    - #### public Process execute()

      Executes the command specified by the given list. The toString() method is called for each item in the list to convert into a resulting String. The first item in the list is the command the others are the parameters.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.0

    - #### public Process execute(String[] envp, File dir)

      Executes the command specified by the given list, with the environment defined by `envp` and under the working directory `dir`. The first item in the list is the command; the others are the parameters. The toString() method is called on items in the list to convert them to Strings.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `envp` - an array of Strings, each member of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.7.1

    - #### public Process execute(List envp, File dir)

      Executes the command specified by the given list, with the environment defined by `envp` and under the working directory `dir`. The first item in the list is the command; the others are the parameters. The toString() method is called on items in the list to convert them to Strings.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `envp` - a List of Objects (converted to Strings using toString), each member of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.7.1

    - #### public Process execute(Map<String, Object> options)

      Executes the command specified by the given list with options provided as named parameters.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `options` - a Map of options to configure the process (see String.execute)
      Returns:
        the Process which has just started
      Since:
        6.0.0
      See Also:
        execute(String, Map)

    - #### <T> public List<T> findAll(Closure closure)

      Finds all values matching the closure condition.

          assert [2,4] == [1,2,3,4].findAll { it % 2 == 0 }

      Parameters:
        `closure` - a closure condition
      Returns:
        a List of matching values
      Since:
        2.4.0

    - #### <T> public List<T> findAll()

      Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth).

      Example:

           def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null]
           assert items.findAll() == [1, 2, true, 'foo', [4, 5]]

      Returns:
        a List of the truthy values
      Since:
        2.4.0
      See Also:
        Closure.IDENTITY

    - #### <T> public T first()

      Returns the first item from the List.

           def list = [3, 4, 2]
           assert list.first() == 3
           // check original is unaltered
           assert list == [3, 4, 2]

      throws:
        NoSuchElementException if you try to access first() for an empty List
      Returns:
        the first item from the List
      Since:
        1.5.5

    - #### <T, E> public List<T> flatten()

      Flatten a List. This List and any nested arrays or collections have their contents (recursively) added to the new List.

          assert [1,2,3,4,5] == [1,[2,3],[[4]],[],5].flatten()

      Returns:
        a flattened List
      Since:
        2.4.0

    - #### <T> public List<T> getAt(Range range)

      Support the range subscript operator for a List.

          def list = [1, "a", 4.5, true]
           assert list[1..2] == ["a", 4.5]

      Parameters:
        `range` - a Range indicating the items to get
      Returns:
        a new list instance based on range borders
      Since:
        1.0

    - #### <T> public List<T> getAt(EmptyRange range)

      Support the range subscript operator for a List.

           def list = [true, 1, 3.4]
           assert list[0..<0] == []

      Parameters:
        `range` - a Range indicating the items to get
      Returns:
        a new list instance based on range borders
      Since:
        1.0

    - #### <T> public List<T> getAt(Collection indices)

      Select a List of items from a List using a Collection to identify the indices to be selected.

          def list = [true, 1, 3.4, false]
           assert list[1,0,2] == [1, true, 3.4]

      Parameters:
        `indices` - a Collection of indices
      Returns:
        a new list of the values at the given indices
      Since:
        1.0

    - #### <T> public T getAt(int idx)

      Support the subscript operator for a List.

          def list = [2, "a", 5.3]
           assert list[1] == "a"

      Parameters:
        `idx` - an index
      Returns:
        the value at the given index
      Since:
        1.0

    - #### <T> public T getAt(Number idx)

      Support subscript operator for list access.

    - #### <T> public List<T> grep(Object filter)

      Iterates over the collection of items and returns each item that matches the given filter - calling the `Object.isCase` method used by switch statements. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Example:

           def list = ['a', 'b', 'aa', 'bc', 3, 4.5]
           assert list.grep( ~/a+/ )  == ['a', 'aa']
           assert list.grep( ~/../ )  == ['aa', 'bc']
           assert list.grep( Number ) == [ 3, 4.5 ]
           assert list.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]

      Parameters:
        `filter` - the filter to perform on each element of the collection (using the Object.isCase method)
      Returns:
        a List of objects which match the filter
      Since:
        2.4.0

    - #### <T> public List<T> grep()

      Iterates over the collection returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.

      Example:

           def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null]
           assert items.grep() == [1, 2, true, 'foo', [4, 5]]

      Returns:
        a List of elements satisfy Groovy truth
      See Also:
        Closure.IDENTITY
      Since:
        2.4.0

    - #### <T> public T head()

      Returns the first item from the List.

          def list = [3, 4, 2]
           assert list.head() == 3
           assert list == [3, 4, 2]

      throws:
        NoSuchElementException if you try to access head() for an empty List
      Returns:
        the first item from the List
      Since:
        1.5.5

    - #### <T> public List<T> init()

      Returns the items from the List excluding the last item. Leaves the original List unchanged.

           def list = [3, 4, 2]
           assert list.init() == [3, 4]
           assert list == [3, 4, 2]

      throws:
        NoSuchElementException if you try to access init() for an empty List
      Returns:
        a List without its last element
      Since:
        2.4.0

    - #### <T> public List<T> intersect(Iterable<T> right)

      Create a List composed of the intersection of a List and an Iterable. Any elements that exist in both iterables are added to the resultant collection.

           assert [4,5] == [1,2,3,4,5].intersect([4,5,6,7,8])

      By default, Groovy uses a NumberAwareComparator when determining if an element exists in both collections.
      Parameters:
        `right` - an Iterable
      Returns:
        a List as an intersection of a List and an Iterable
      See Also:
        intersect(List, Iterable, Comparator)
      Since:
        2.4.0

    - #### <T> public List<T> intersect(Iterable<T> right, Comparator<? super T> comparator)

      Create a List composed of the intersection of a List and an Iterable. Any elements that exist in both iterables are added to the resultant collection.

           assert [3,4] == [1,2,3,4].intersect([3,4,5,6])

      Parameters:
        `right` - an Iterable
        `comparator` - a Comparator
      Returns:
        a List as an intersection of a List and an Iterable
      Since:
        2.5.0

    - #### <T> public T last()

      Returns the last item from the List.

           def list = [3, 4, 2]
           assert list.last() == 2
           // check original is unaltered
           assert list == [3, 4, 2]

      throws:
        NoSuchElementException if you try to access last() for an empty List
      Returns:
        the last item from the List
      Since:
        1.5.5

    - #### <T> public List<T> leftShift(T value)

      Overloads the left shift operator to provide an easy way to append objects to a List.

          def list = [1,2]
           list << 3
           assert list == [1,2,3]

      Parameters:
        `value` - an Object to be added to the List.
      Returns:
        same List, after the value was added to it.
      Since:
        2.4.0

    - #### <T> public List<T> minus(Collection<?> removeMe)

      Create a List composed of the elements of the given List minus every occurrence of elements of the given Collection.

           def one = [1, "a", true, true, false, 5.3, null], two = [null, true, 5.3]
           def sub = one.asUnmodifiable() - two.asUnmodifiable()
           assert sub == [1, "a", false]

      Parameters:
        `removeMe` - the elements to exclude
      Returns:
        a new List
      Since:
        1.0

    - #### <T> public List<T> minus(Iterable<?> removeMe)

      Create a new List composed of the elements of the first List minus every occurrence of elements of the given Iterable.

          assert [1, "a", true, true, false, 5.3] - [true, 5.3] == [1, "a", false]

      Parameters:
        `removeMe` - the elements to exclude
      Returns:
        a new List
      Since:
        1.8.7

    - #### <T> public List<T> minus(Object removeMe)

      Create a new List composed of the elements of the first List minus every occurrence of the given element to remove.

          assert ["a", 5, 5, true] - 5 == ["a", true]

      Parameters:
        `removeMe` - the element to exclude
      Returns:
        a new List
      Since:
        1.0

    - #### <T> public List<T> multiply(Number factor)

      Create a List composed of the elements of this Iterable, repeated a certain number of times. Note that for non-primitive elements, multiple references to the same instance will be added.

          assert [1,2,3,1,2,3] == [1,2,3] * 2

      Note: if the Iterable happens to not support duplicates, e.g. a Set, then the method will effectively return a Collection with a single copy of the Iterable's items.
      Parameters:
        `factor` - the number of times to append
      Returns:
        the multiplied List
      Since:
        2.4.0

    - #### <T> public int partitionPoint(IntRange range, Predicate<? super T> condition)

      Returns the index of the partition point according to the given predicate (the index of the first element of the second partition). The list is assumed to be partitioned according to the given predicate.

           def list = [7, 15, 3, 5, 4, 12, 6]
           assert list.partitionPoint(0..<list.size()) { it%2 != 0 } == 4

           def list = [1, 2, 3, 3, 4, 4, 5, 6, 7]
           // usage case as lower_bound(cpp), bisect_left(python)
           assert list.partitionPoint(0..<list.size()) { it < 4 } == 4
           // usage case as upper_bound(cpp), bisect_right(python)
           assert list.partitionPoint(0..<list.size()) { it <= 4 } == 6
           // for all match condition
           assert list.partitionPoint(0..<list.size()) { it <= 20 } == list.size()
           // for no match condition
           assert list.partitionPoint(0..<list.size()) { it <= 0 } == 0
           // for all match condition with range
           assert list.partitionPoint(0..<4) { it <= 20 } == 4
           // for no match condition with range
           assert list.partitionPoint(2..<list.size()) { it <= 0 } == 2

      Parameters:
        `range` - the range [l,r] to find data match the condition
        `condition` - the matching condition
      Returns:
        an integer that is the index of the first element of the second partition
      Since:
        5.0.0

    - #### <T> public int partitionPoint(Predicate<? super T> condition)

      Returns the index of the partition point according to the given predicate (the index of the first element of the second partition). The list is assumed to be partitioned according to the given predicate.

           def list = [7, 15, 3, 5, 4, 12, 6] // partitioned into odds then evens
           assert list.partitionPoint{ it%2 != 0 } == 4

           def list = [1, 2, 3, 3, 4, 4, 5, 6, 7]
           // usage case as lower_bound(cpp), bisect_left(python)
           assert list.partitionPoint{ it < 4 } == 4
           // usage case as upper_bound(cpp), bisect_right(python)
           assert list.partitionPoint{ it <= 4 } == 6
           // for all match condition
           assert list.partitionPoint{ it <= 100 } == list.size()
           // for no match condition
           assert list.partitionPoint{ it <= 0 } == 0
           // predicate of reverse logic examples:
           assert [7, 6, 5, 4, 4, 3, 3, 2, 1].partitionPoint{ it > 4 } == 3
           assert [7, 6, 5, 4, 4, 3, 3, 2, 1].partitionPoint{ it >= 4 } == 5
           // empty input
           assert [].partitionPoint{ it < 4 } == 0

      Parameters:
        `condition` - the matching condition
      Returns:
        an integer that is the index of the first element of the second partition
      Since:
        5.0.0

    - #### public List<Process> pipeline()

      Creates a native OS pipeline from a list of commands, using ProcessBuilder.startPipeline. Each element in the list can be a String (tokenized on whitespace), a List (elements converted to Strings via `toString()`), a String array, or a ProcessBuilder for full control.

           def procs = ["ps aux", "grep java", "wc -l"].pipeline()
           println procs.last().text

      throws:
        IOException if an IOException occurs.
      Returns:
        the list of started Process instances
      Since:
        6.0.0

    - #### <T> public List<T> plus(Iterable<T> right)

      Create a List as a union of a List and an Iterable. This operation will always create a new object for the result, while the operands remain unchanged.

      Parameters:
        `right` - the right Iterable
      Returns:
        the merged List
      Since:
        2.4.0
      See Also:
        plus(Collection, Collection)

    - #### <T> public List<T> plus(Collection<T> right)

      Create a List as a union of a List and a Collection. This operation will always create a new object for the result, while the operands remain unchanged.

      Parameters:
        `right` - the right Collection
      Returns:
        the merged List
      Since:
        2.4.0
      See Also:
        plus(Collection, Collection)

    - #### <T> public List<T> plus(int index, T[] items)

      Creates a new List by inserting all the elements in the specified array to the elements from the original List at the specified index. Shifts the element currently at that index (if any) and any subsequent elements to the right (increasing their indices). The new elements will appear in the resulting List in the order that they occur in the original array. The behavior of this operation is undefined if the list or array operands are modified while the operation is in progress. The original list and array operands remain unchanged.

           def items = [1, 2, 3]
           def newItems = items.plus(2, 'a'..'c' as String[])
           assert newItems == [1, 2, 'a', 'b', 'c', 3]
           assert items == [1, 2, 3]

      See also `addAll` for similar functionality with modify semantics, i.e. which performs the changes on the original list itself.
      Parameters:
        `items` - array containing elements to be merged with elements from the original list
        `index` - index at which to insert the first element from the specified array
      Returns:
        the new list
      See Also:
        plus(List, int, List)
      Since:
        1.8.1

    - #### <T> public List<T> plus(int index, List<T> additions)

      Creates a new List by inserting all the elements in the given additions List to the elements from the original List at the specified index. Shifts the element currently at that index (if any) and any subsequent elements to the right (increasing their indices). The new elements will appear in the resulting List in the order that they occur in the original lists. The behavior of this operation is undefined if the original lists are modified while the operation is in progress. The original lists remain unchanged.

           def items = [1, 2, 3]
           def newItems = items.plus(2, 'a'..'c')
           assert newItems == [1, 2, 'a', 'b', 'c', 3]
           assert items == [1, 2, 3]

      See also `addAll` for similar functionality with modify semantics, i.e. which performs the changes on the original list itself.
      Parameters:
        `additions` - a List containing elements to be merged with elements from the original List
        `index` - index at which to insert the first element from the given additions List
      Returns:
        the new list
      Since:
        1.8.1

    - #### <T> public List<T> plus(int index, Iterable<T> additions)

      Creates a new List by inserting all the elements in the given Iterable to the elements from this List at the specified index.

      Parameters:
        `additions` - an Iterable containing elements to be merged with the elements from the original List
        `index` - index at which to insert the first element from the given additions Iterable
      Returns:
        the new list
      Since:
        1.8.7
      See Also:
        plus(List, int, List)

    - #### <T> public List<T> plus(T right)

      Create a List as a union of a List and an Object. This operation will always create a new object for the result, while the operands remain unchanged.

          assert [1,2,3] == [1,2] + 3

      Parameters:
        `right` - an object to add/append
      Returns:
        the resulting List
      Since:
        2.4.0

    - #### <T> public T pop()

      Removes the initial item from the List.

           def list = ["a", false, 2]
           assert list.pop() == 'a'
           assert list == [false, 2]

      This is similar to pop on a Stack where the first item in the list represents the top of the stack. Note: The behavior of this method changed in Groovy 2.5 to align with Java. If you need the old behavior use 'removeLast'.
      throws:
        NoSuchElementException if the list is empty
      Returns:
        the item removed from the List
      Since:
        1.0

    - #### <T> public boolean push(T value)

      Prepends an item to the start of the List.

           def list = [3, 4, 2]
           list.push("x")
           assert list == ['x', 3, 4, 2]

      This is similar to push on a Stack where the first item in the list represents the top of the stack. Note: The behavior of this method changed in Groovy 2.5 to align with Java. If you need the old behavior use 'add'.
      Parameters:
        `value` - element to be prepended to this list.
      Returns:
        `true` (for legacy compatibility reasons).
      Since:
        1.5.5

    - #### <T> public void putAt(int idx, T value)

      A helper method to allow lists to work with subscript operators.

          def list = [2, 3]
           list[0] = 1
           assert list == [1, 3]

      Parameters:
        `idx` - an index
        `value` - the value to put at the given index
      Since:
        1.0

    - #### <T> public void putAt(Number idx, T value)

      Support subscript operator for list modification.

    - #### public void putAt(EmptyRange range, Object value)

      A helper method to allow lists to work with subscript operators.

           def list = ["a", true]
           list[1..<1] = 5
           assert list == ["a", 5, true]

      Parameters:
        `range` - the (in this case empty) subset of the list to set
        `value` - the values to put at the given sublist or a Collection of values
      Since:
        1.0

    - #### public void putAt(EmptyRange range, Collection value)

      A helper method to allow lists to work with subscript operators.

           def list = ["a", true]
           list[1..<1] = [4, 3, 2]
           assert list == ["a", 4, 3, 2, true]

      Parameters:
        `range` - the (in this case empty) subset of the list to set
        `value` - the Collection of values
      Since:
        1.0
      See Also:
        putAt(java.util.List, groovy.lang.EmptyRange, java.lang.Object)

    - #### public void putAt(IntRange range, Collection col)

      List subscript assignment operator when given a range as the index and the assignment operand is a collection. Example:

          def myList = [4, 3, 5, 1, 2, 8, 10]
           myList[3..5] = ["a", true]
           assert myList == [4, 3, 5, "a", true, 10]

      Items in the given range are replaced with items from the collection.
      Parameters:
        `range` - the subset of the list to set
        `col` - the collection of values to put at the given sublist
      Since:
        1.5.0

    - #### public void putAt(IntRange range, Object value)

      List subscript assignment operator when given a range as the index. Example:

          def myList = [4, 3, 5, 1, 2, 8, 10]
           myList[3..5] = "b"
           assert myList == [4, 3, 5, "b", 10]

      Items in the given range are replaced with the operand. The `value` operand is always treated as a single value.
      Parameters:
        `range` - the subset of the list to set
        `value` - the value to put at the given sublist
      Since:
        1.0

    - #### public void putAt(List splice, Collection values)

      A helper method to allow lists to work with subscript operators.

          def list = ["a", true, 42, 9.4]
           list[1, 4] = ["x", false]
           assert list == ["a", "x", 42, 9.4, false]

      Parameters:
        `splice` - the subset of the list to set
        `values` - the value to put at the given sublist
      Since:
        1.0

    - #### public void putAt(List splice, Object value)

      A helper method to allow lists to work with subscript operators.

          def list = ["a", true, 42, 9.4]
           list[1, 3] = 5
           assert list == ["a", 5, 42, 5]

      Parameters:
        `splice` - the subset of the list to set
        `value` - the value to put at the given sublist
      Since:
        1.0

    - #### <E> public E removeAt(int index)

      Modifies this list by removing the element at the specified position in this list. Returns the removed element. Essentially an alias for List.remove but with no ambiguity for List<Integer>.

      Example:

           def list = [1, 2, 3]
           list.removeAt(1)
           assert [1, 3] == list

      Parameters:
        `index` - the index of the element to be removed
      Returns:
        the element previously at the specified position
      Since:
        2.4.0

    - #### <T> public T removeLast()

      Removes the last item from the List.

           def list = ['a', false, 2]
           assert list.removeLast() == 2
           assert list == ['a', false]

      Using add() and removeLast() is similar to push and pop on a Stack where the last item in the list represents the top of the stack.
      throws:
        NoSuchElementException if the list is empty
      Returns:
        the item removed from the List
      Since:
        2.5.0

    - #### <T> public List<T> reverse()

      Creates a new List with the identical contents to this list but in reverse order.

           def list = ["a", 4, false]
           assert list.reverse() == [false, 4, "a"]
           assert list == ["a", 4, false]

      Returns:
        a reversed List
      See Also:
        reverse(List, boolean)
      Since:
        1.0

    - #### <T> public List<T> reverse(boolean mutate)

      Reverses the elements in a list. If mutate is true, the original list is modified in place and returned. Otherwise, a new list containing the reversed items is produced.

           def list = ["a", 4, false]
           assert list.reverse(false) == [false, 4, "a"]
           assert list == ["a", 4, false]
           assert list.reverse(true) == [false, 4, "a"]
           assert list == [false, 4, "a"]

      Parameters:
        `mutate` - true if the list itself should be reversed in place and returned, false if a new list should be created
      Returns:
        a reversed List
      Since:
        1.8.1

    - #### <T> public List<T> reverseEach(Closure closure)

      Iterate over each element of the list in the reverse order.

          def result = []
           [1,2,3].reverseEach { result << it }
           assert result == [3,2,1]

      Parameters:
        `closure` - a closure to which each item is passed.
      Returns:
        the original list
      Since:
        1.5.0

    - #### public void shuffle()

      Randomly reorders the elements of the specified list.

           def list = ["a", 4, false]
           def origSize = list.size()
           def origCopy = new ArrayList(list)
           list.shuffle()
           assert list.size() == origSize
           assert origCopy.every{ list.contains(it) }

      See Also:
        Collections.shuffle
      Since:
        3.0.0

    - #### public void shuffle(Random rnd)

      Randomly reorders the elements of the specified list using the specified random instance as the source of randomness.

           def r = new Random()
           def list = ["a", 4, false]
           def origSize = list.size()
           def origCopy = new ArrayList(list)
           list.shuffle(r)
           assert list.size() == origSize
           assert origCopy.every{ list.contains(it) }

      See Also:
        Collections.shuffle
      Since:
        3.0.0

    - #### <T> public List<T> shuffled()

      Creates a new list containing the elements of the specified list but in a random order.

           def list = ["a", 4, false]
           def result = list.shuffled()
           assert list !== result
           assert list == ["a", 4, false]
           assert list.size() == result.size()
           assert list.every{ result.contains(it) }

      See Also:
        Collections.shuffle
      Since:
        3.0.0

    - #### <T> public List<T> shuffled(Random rnd)

      Creates a new list containing the elements of the specified list but in a random order using the specified random instance as the source of randomness.

           def r = new Random()
           def list = ["a", 4, false]
           def result = list.shuffled(r)
           assert list !== result
           assert list == ["a", 4, false]
           assert list.size() == result.size()
           assert list.every{ result.contains(it) }

      See Also:
        Collections.shuffle
      Since:
        3.0.0

    - #### <T> public List<T> sort(IntRange range, boolean mutate, Comparator<? super T> comparator)

      Sorts the Iterable using the given Comparator over the given index range. If the Iterable is a List and mutate is true, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned - leaving the original Iterable unchanged.

           def orig = ['hello', 'hi', 'Hey', 'a']
           def sorted = orig.sort(0..2, false, String.CASE_INSENSITIVE_ORDER)
           assert orig == ['hello', 'hi', 'Hey', 'a']
           assert sorted == ['hello', 'Hey', 'hi', 'a']

      Parameters:
        `range` - the inclusive range of index values over which to sort
        `mutate` - false causes a new list to be created, true will mutate lists in place
        `comparator` - a Comparator used for the comparison
      Returns:
        a sorted List
      Since:
        5.0.0

    - #### <T> public List<T> sort(IntRange range, Comparator<? super T> comparator)

      Sorts the Iterable using the given Comparator over the given index range.

           def orig = ['hello', 'hi', 'Hey', 'a']
           orig.sort(0..2, String.CASE_INSENSITIVE_ORDER)
           assert orig == ['hello', 'Hey', 'hi', 'a']

      Parameters:
        `range` - the inclusive range of index values over which to sort
        `comparator` - a Comparator used for the comparison
      Returns:
        a sorted List
      Since:
        5.0.0

    - #### <T> public List<T> sort(IntRange range, boolean mutate, Closure<?> closure)

      Sorts elements in the given index range using the given Closure to determine the ordering. If mutate is true, it is sorted in place and returned. Otherwise, the elements are first placed into a new list which is then sorted and returned, leaving the original List unchanged.

           // a list with some odd then even numbers
           def nums = [5, 9, 1, 7, 3, 4, 8, 6, 0, 2]

           // sort odds ascending, evens descending
           assert nums.sort(0..4, false) { it }.sort(5..9, false) { -it }
            == [1, 3, 5, 7, 9, 8, 6, 4, 2, 0]
           // sort odds descending, evens descending
           assert nums.sort(0..<5, false) { -it }.sort(4<..<10, false) { -it }
            == [9, 7, 5, 3, 1, 8, 6, 4, 2, 0]
           // sort odds descending, evens ascending
           assert nums.sort(0..<5, false) { -it }.sort(5..-1, false) { it }
            == [9, 7, 5, 3, 1, 0, 2, 4, 6, 8]
           // leave first and last numbers, sort remaining odds ascending, remaining evens descending
           assert nums.sort(1..4, false) { it }.sort(5..-2, false) { -it }
            == [5, 1, 3, 7, 9, 8, 6, 4, 0, 2]
           // leave first and last numbers, sort remaining odds descending, remaining evens ascending
           assert nums.sort(1..4, false) { -it }.sort(5..-2, false) { it }
            == [5, 9, 7, 3, 1, 0, 4, 6, 8, 2]
           // leave first and last odds and evens, sort remaining odds ascending, remaining evens descending
           assert nums.sort(0<..<4, false) { it }.sort(5<..<9, false) { -it }
            == [5, 1, 7, 9, 3, 4, 8, 6, 0, 2]
           // leave first and last odds and evens, sort remaining odds descending, remaining evens ascending
           assert nums.sort(0<..<4, false) { -it }.sort(5<..<-1, false) { it }
            == [5, 9, 7, 1, 3, 4, 0, 6, 8, 2]

      Parameters:
        `range` - the inclusive range of index values over which to sort
        `mutate` - false causes a new list to be created, true will mutate lists in place
        `closure` - a Closure used to determine the correct ordering
      Returns:
        a sorted List
      Since:
        5.0.0

    - #### <T> public List<T> sort(IntRange range, Closure<?> closure)

      A sort variant that takes an index range and always mutates the original list.

           def nums = [5, 9, 1, 7, 3, 4, 8, 6, 0, 2]
           nums.sort(0..4) { it }
           assert nums == [1, 3, 5, 7, 9, 4, 8, 6, 0, 2]

      See Also:
        sort(List, IntRange, boolean, Closure)
      Returns:
        the sorted list
      Since:
        5.0.0

    - #### <T> public List<T> sort(IntRange range)

      A mutating sort variant that takes an index range.

           def nums = [5, 9, 1, 7, 3, 4, 8, 6, 0, 2]
           nums.sort(0..4)
           assert nums == [1, 3, 5, 7, 9, 4, 8, 6, 0, 2]

      See Also:
        sort(List, IntRange, boolean, Closure)
      Returns:
        the sorted list
      Since:
        5.0.0

    - #### <T> public List<List<T>> split(Closure closure)

      Splits all items into two collections based on the closure condition. The first list contains all items which match the closure expression. The second list all those that don't.

      Example usage:

          assert [[2,4],[1,3]] == [1,2,3,4].split { it % 2 == 0 }

      Parameters:
        `closure` - a closure condition
      Returns:
        a List whose first item is the accepted values and whose second item is the rejected values
      Since:
        2.4.0

    - #### <T> public List<List<T>> split(Predicate<? super T> predicate)

      Splits all items into two lists based on the predicate. A "fat-free" variant of List.split accepting a Predicate.

           assert [[2, 4], [1, 3]] == [1, 2, 3, 4].split(n -> n % 2 == 0)

      Parameters:
        `predicate` - a predicate used to determine the target list
      Returns:
        a List whose first item is the accepted values and whose second item is the rejected values
      Since:
        6.0.0

    - #### <T> public List<T> subList(IntRange range)

      Returns a view of the portion of this list given by the specified range.

           def nums = [0, 1, 2, 3, 4]
           assert nums.subList(1..3) == 1..3
           assert nums.subList(0<..<-1) == 1..3
           nums.subList(1..3).clear()
           assert nums == [0, 4]

      Parameters:
        `range` - a range
      Returns:
        a view of the specified range within this list
      Since:
        5.0.0

    - #### <T> public Set<List<T>> subsequences()

      Finds all non-null subsequences of a list.

      Example usage:

          def result = [1, 2, 3].subsequences()
           assert result == [[1, 2, 3], [1, 3], [2, 3], [1, 2], [1], [2], [3]] as Set

      Returns:
        the subsequences from the list
      Since:
        1.7.0

    - #### <T> public List<T> swap(int i, int j)

      Swaps two elements at the specified positions.

      Example:

           assert [1, 3, 2, 4] == [1, 2, 3, 4].swap(1, 2)

      Parameters:
        `i` - a position
        `j` - a position
      Returns:
        self
      See Also:
        Collections.swap
      Since:
        2.4.0

    - #### <T> public List<T> tail()

      Returns the items from the List excluding the first item.

           def list = [3, 4, 2]
           assert list.tail() == [4, 2]
           assert list == [3, 4, 2]

      throws:
        NoSuchElementException if you try to access tail() for an empty List
      Returns:
        a List without its first element
      Since:
        1.5.6

    - #### <T> public List<T> take(int num)

      Returns the first `num` elements from the head of this List.

           def strings = [ 'a', 'b', 'c' ]
           assert strings.take( 0 ) == []
           assert strings.take( 2 ) == [ 'a', 'b' ]
           assert strings.take( 5 ) == [ 'a', 'b', 'c' ]

      Parameters:
        `num` - the number of elements to take from this List
      Returns:
        a List consisting of the first `num` elements from this List, or else all the elements from the List if it has less than `num` elements.
      Since:
        1.8.1

    - #### <T> public List<T> takeRight(int num)

      Returns the last `num` elements from the tail of this List.

           def strings = [ 'a', 'b', 'c' ]
           assert strings.takeRight( 0 ) == []
           assert strings.takeRight( 2 ) == [ 'b', 'c' ]
           assert strings.takeRight( 5 ) == [ 'a', 'b', 'c' ]

      Parameters:
        `num` - the number of elements to take from this List
      Returns:
        a List consisting of the last `num` elements from this List, or else all the elements from the List if it has less than `num` elements.
      Since:
        2.4.0

    - #### <T> public List<T> takeWhile(Closure condition)

      Returns the longest prefix of this list where each element passed to the given closure condition evaluates to true. Similar to Iterable#takeWhile(groovy.lang.Closure) except that it attempts to preserve the type of the original list.

           def nums = [ 1, 3, 2 ]
           assert nums.takeWhile{ it < 1 } == []
           assert nums.takeWhile{ it < 3 } == [ 1 ]
           assert nums.takeWhile{ it < 4 } == [ 1, 3, 2 ]

      Parameters:
        `condition` - the closure that must evaluate to true to continue taking elements
      Returns:
        a prefix of the given list where each element passed to the given closure evaluates to true
      Since:
        1.8.7

    - #### <T> public List<T> takeWhile(Predicate<? super T> condition)

      Returns the longest prefix of a List where each element passes the given predicate. A "fat-free" variant of List.takeWhile accepting a Predicate.

           assert [1, 2, 3, 0, 4].takeWhile(n -> n < 3) == [1, 2]

      Parameters:
        `condition` - the predicate that must evaluate to true to continue taking elements
      Returns:
        a prefix of the given list where each element passes the given predicate
      Since:
        6.0.0

    - #### public ProcessBuilder toProcessBuilder()

      Creates a ProcessBuilder from a command list. The toString() method is called for each item in the list to convert into a resulting String.

      Returns:
        a ProcessBuilder ready to be configured further or started
      Since:
        6.0.0

    - #### <T> public List<T> toSorted(IntRange range, Closure<?> closure)

      A sort variant that takes an index range and never modifies the original list.

           def nums = [5, 9, 1, 7, 3, 4, 8, 6, 0, 2]
           assert nums.toSorted(0..4) { it } == [1, 3, 5, 7, 9, 4, 8, 6, 0, 2]

      Parameters:
        `range` - the inclusive range of index values over which to sort
        `closure` - a Closure used for the comparison
      See Also:
        sort(List, IntRange, boolean, Closure)
      Returns:
        the sorted list
      Since:
        5.0.0

    - #### <T> public List<T> toSorted(IntRange range, Comparator<? super T> comparator)

      Returns a list, sorted over the given range using a NumberAwareComparator, leaving the original list unmodified.

           def nums = [5, 9, 1, 7, 3, 4, 8, 6, 0, 2]
           assert nums.toSorted(0..4, Comparator.reverseOrder()) == [9, 7, 5, 3, 1, 4, 8, 6, 0, 2]
           assert nums.toSorted(5..-1, Comparator.reverseOrder()) == [5, 9, 1, 7, 3, 8, 6, 4, 2, 0]

      Parameters:
        `range` - the inclusive range of index values over which to sort
        `comparator` - a Comparator used for the comparison
      See Also:
        sort(List, IntRange, boolean, Comparator)
      Returns:
        the sorted list
      Since:
        5.0.0

    - #### <T> public List<T> toSorted(IntRange range)

      Returns a list, sorted over the given range using a NumberAwareComparator, leaving the original list unmodified.

           def nums = [5, 9, 1, 7, 3, 4, 8, 6, 0, 2]
           assert nums.toSorted(0..4) == [1, 3, 5, 7, 9, 4, 8, 6, 0, 2]
           assert nums.toSorted(5..-1) == [5, 9, 1, 7, 3, 0, 2, 4, 6, 8]

      Parameters:
        `range` - the inclusive range of index values over which to sort
      See Also:
        toSorted(List, IntRange, Closure)
      Returns:
        the sorted list
      Since:
        5.0.0

    - #### public SpreadMap toSpreadMap()

      Creates a spreadable map from this list.

      Returns:
        a newly created SpreadMap
      See Also:
        SpreadMap.SpreadMap
        toSpreadMap(java.util.Map)
      Since:
        1.8.0

    - #### <T> public List<T> toUnique(Comparator<? super T> comparator)

      Returns a List containing the items from the List but with duplicates removed. The items in the List are compared by the given Comparator. For each duplicate, the first member which is returned from the List is retained, but all other ones are removed.

           class Person {
               def fname, lname
               String toString() {
                   return fname + " " + lname
               }
           }

           class PersonComparator implements Comparator {
               int compare(Object o1, Object o2) {
                   Person p1 = (Person) o1
                   Person p2 = (Person) o2
                   if (p1.lname != p2.lname)
                       return p1.lname.compareTo(p2.lname)
                   else
                       return p1.fname.compareTo(p2.fname)
               }

               boolean equals(Object obj) {
                   return this.equals(obj)
               }
           }

           Person a = new Person(fname:"John", lname:"Taylor")
           Person b = new Person(fname:"Clark", lname:"Taylor")
           Person c = new Person(fname:"Tom", lname:"Cruz")
           Person d = new Person(fname:"Clark", lname:"Taylor")

           def list = [a, b, c, d]
           List list2 = list.toUnique(new PersonComparator())
           assert list2 == [a, b, c] && list == [a, b, c, d]

      Parameters:
        `comparator` - a Comparator used to determine unique (equal) items If `null`, the Comparable natural ordering of the elements will be used.
      Returns:
        the List of non-duplicate items
      Since:
        2.4.0

    - #### <T> public List<T> toUnique()

      Returns a List containing the items from the List but with duplicates removed using the natural ordering of the items to determine uniqueness.

           def letters = ['c', 'a', 't', 's', 'a', 't', 'h', 'a', 't']
           def expected = ['c', 'a', 't', 's', 'h']
           assert letters.toUnique() == expected

      Returns:
        the List of non-duplicate items
      Since:
        2.4.0

    - #### <T> public List<T> toUnique(Closure condition)

      Returns a List containing the items from the List but with duplicates removed. The items in the List are compared by the given Closure condition. For each duplicate, the first member which is returned from the Iterable is retained, but all other ones are removed.

      If the closure takes a single parameter, each element from the Iterable will be passed to the closure. The closure should return a value used for comparison (either using Comparable.compareTo or Object.equals). If the closure takes two parameters, two items from the Iterable will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).

           class Person {
               def fname, lname
               String toString() {
                   return fname + " " + lname
               }
           }

           Person a = new Person(fname:"John", lname:"Taylor")
           Person b = new Person(fname:"Clark", lname:"Taylor")
           Person c = new Person(fname:"Tom", lname:"Cruz")
           Person d = new Person(fname:"Clark", lname:"Taylor")

           def list = [a, b, c, d]
           def list2 = list.toUnique{ p1, p2 -> p1.lname != p2.lname ? p1.lname <=> p2.lname : p1.fname <=> p2.fname }
           assert( list2 == [a, b, c] && list == [a, b, c, d] )
           def list3 = list.toUnique{ it.toString() }
           assert( list3 == [a, b, c] && list == [a, b, c, d] )

      Parameters:
        `condition` - a Closure used to determine unique items
      Returns:
        a new List
      See Also:
        toUnique(Iterable, Comparator)
      Since:
        2.4.0

    - #### public List transpose()

      Adds GroovyCollections#transpose(List) as a method on lists. A Transpose Function takes a collection of columns and returns a collection of rows. The first row consists of the first element from each column. Successive rows are constructed similarly.

      Example usage:

           def result = [['a', 'b'], [1, 2]].transpose()
           assert result == [['a', 1], ['b', 2]]

           def result = [['a', 'b'], [1, 2], [3, 4]].transpose()
           assert result == [['a', 1, 3], ['b', 2, 4]]

      Returns:
        a List of the transposed lists
      See Also:
        GroovyCollections.transpose
      Since:
        1.5.0

    - #### <T> public List<T> union(Iterable<T> right)

      Create a List composed of the union of a List and an Iterable. Any elements that exist in both iterables are added to the resultant collection, such that no elements are duplicated in the resultant collection.

           assert [1,2,3,4,5,6,7,8] == [1,2,3,4,5].union([4,5,6,7,8])

      By default, Groovy uses a NumberAwareComparator when determining if an element already exists in the resultant collection.
      Parameters:
        `right` - an Iterable
      Returns:
        a List as a union of a List and an Iterable
      See Also:
        union(List, Iterable, Comparator)
      Since:
        5.0.0

    - #### <T> public List<T> union(Iterable<T> right, Comparator<? super T> comparator)

      Create a List composed of the union of a List and an Iterable. Any elements that exist in either iterables are added to the resultant collection, such that no elements are duplicated in the resultant collection.

           assert [1,2,3,4,5,6] == [1,2,3,4].union([3,4,5,6])

      Parameters:
        `right` - an Iterable
        `comparator` - a Comparator
      Returns:
        a List as a union of a List and an Iterable
      Since:
        5.0.0

    - #### <T> public List<T> unique()

      Modifies this List to remove all duplicated items, using Groovy's default number-aware comparator.

          assert [1,3] == [1,3,3].unique()

      Returns:
        the now modified List
      See Also:
        unique(Collection, boolean)
      Since:
        2.4.0

    - #### <T> public List<T> unique(boolean mutate)

      Remove all duplicates from a given List using Groovy's default number-aware comparator. If mutate is true, it works by modifying the original object (and also returning it). If mutate is false, a new collection is returned leaving the original unchanged.

           assert [1,3] == [1,3,3].unique()

           def orig = [1, 3, 2, 3]
           def uniq = orig.unique(false)
           assert orig == [1, 3, 2, 3]
           assert uniq == [1, 3, 2]

      Parameters:
        `mutate` - false will cause a new List containing unique items from the List to be created, true will mutate List in place
      Returns:
        the now modified List
      Since:
        2.4.0

    - #### <T> public List<T> unique(Closure closure)

      A convenience method for making a List unique using a Closure to determine duplicate (equal) items.

      If the closure takes a single parameter, the argument passed will be each element, and the closure should return a value used for comparison (either using Comparable.compareTo or Object.equals). If the closure takes two parameters, two items from the List will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).

          assert [1,4] == [1,3,4,5].unique { it % 2 }

          assert [2,3,4] == [2,3,3,4].unique { a, b -> a <=> b }

      Parameters:
        `closure` - a 1 or 2 arg Closure used to determine unique items
      Returns:
        self without any duplicates
      See Also:
        unique(Collection, boolean, Closure)
      Since:
        2.4.0

    - #### <T> public List<T> unique(boolean mutate, Closure closure)

      A convenience method for making a List unique using a Closure to determine duplicate (equal) items. If mutate is true, it works on the receiver object and returns it. If mutate is false, a new collection is returned.

      If the closure takes a single parameter, each element from the List will be passed to the closure. The closure should return a value used for comparison (either using Comparable.compareTo or Object.equals). If the closure takes two parameters, two items from the collection will be passed as arguments, and the closure should return an int value (with 0 indicating the items are not unique).

           def orig = [1, 3, 4, 5]
           def uniq = orig.unique(false) { it % 2 }
           assert orig == [1, 3, 4, 5]
           assert uniq == [1, 4]

           def orig = [2, 3, 3, 4]
           def uniq = orig.unique(false) { a, b -> a <=> b }
           assert orig == [2, 3, 3, 4]
           assert uniq == [2, 3, 4]

      Parameters:
        `mutate` - false will always cause a new list to be created, true will mutate lists in place
        `closure` - a 1 or 2 arg Closure used to determine unique items
      Returns:
        self without any duplicates
      Since:
        2.4.0

    - #### <T> public List<T> unique(Comparator<? super T> comparator)

      Remove all duplicates from a given List. Works on the original object (and also returns it). The order of members in the List are compared by the given Comparator. For each duplicate, the first member which is returned by the given List's iterator is retained, but all other ones are removed. The given List's original order is preserved.

           class Person {
               def fname, lname
               String toString() {
                   return fname + " " + lname
               }
           }

           class PersonComparator implements Comparator {
               int compare(Object o1, Object o2) {
                   Person p1 = (Person) o1
                   Person p2 = (Person) o2
                   if (p1.lname != p2.lname)
                       return p1.lname.compareTo(p2.lname)
                   else
                       return p1.fname.compareTo(p2.fname)
               }

               boolean equals(Object obj) {
                   return this.equals(obj)
               }
           }

           Person a = new Person(fname:"John", lname:"Taylor")
           Person b = new Person(fname:"Clark", lname:"Taylor")
           Person c = new Person(fname:"Tom", lname:"Cruz")
           Person d = new Person(fname:"Clark", lname:"Taylor")

           def list = [a, b, c, d]
           List list2 = list.unique(new PersonComparator())
           assert( list2 == list && list == [a, b, c] )

      Parameters:
        `comparator` - a Comparator
      Returns:
        self the now modified List without duplicates
      See Also:
        unique(java.util.Collection, boolean, java.util.Comparator)
      Since:
        2.4.0

    - #### <T> public List<T> unique(boolean mutate, Comparator<? super T> comparator)

      Remove all duplicates from a given List. If mutate is true, it works on the original object (and also returns it). If mutate is false, a new List is returned. The order of members in the List are compared by the given Comparator. For each duplicate, the first member which is returned by the given List's iterator is retained, but all other ones are removed. The given List's original order is preserved.

           class Person {
               def fname, lname
               String toString() {
                   return fname + " " + lname
               }
           }

           class PersonComparator implements Comparator {
               int compare(Object o1, Object o2) {
                   Person p1 = (Person) o1
                   Person p2 = (Person) o2
                   if (p1.lname != p2.lname)
                       return p1.lname.compareTo(p2.lname)
                   else
                       return p1.fname.compareTo(p2.fname)
               }

               boolean equals(Object obj) {
                   return this.equals(obj)
               }
           }

           Person a = new Person(fname:"John", lname:"Taylor")
           Person b = new Person(fname:"Clark", lname:"Taylor")
           Person c = new Person(fname:"Tom", lname:"Cruz")
           Person d = new Person(fname:"Clark", lname:"Taylor")

           def list = [a, b, c, d]
           List list2 = list.unique(false, new PersonComparator())
           assert( list2 != list && list2 == [a, b, c] )

      Parameters:
        `mutate` - false will always cause a new List to be created, true will mutate List in place
        `comparator` - a Comparator
      Returns:
        self the List without duplicates
      Since:
        2.4.0

    - #### <T> public ListWithDefault<T> withDefault(Closure<T> init)

      An alias for `withLazyDefault` which decorates a list allowing it to grow when called with index values outside the normal list bounds.

      Parameters:
        `init` - a Closure with the target index as parameter which generates the default value
      Returns:
        the decorated List
      See Also:
        withLazyDefault(java.util.List, groovy.lang.Closure)
        withEagerDefault(java.util.List, groovy.lang.Closure)
      Since:
        1.8.7

    - #### <T> public ListWithDefault<T> withEagerDefault(Closure<T> init)

      Decorates a list allowing it to grow when called with a non-existent index value. When called with such values, the list is grown in size and a default value is placed in the list by calling a supplied `init` Closure. Null values can be stored in the list.

      How it works: The decorated list intercepts all calls to `getAt(index)` and `get(index)`. If an index greater than or equal to the current `size()` is used, the list will grow automatically up to the specified index. Gaps will be filled by calling the `init` Closure. If generating a default value is a costly operation consider using `withLazyDefault`.

      Example usage:

           def list = [0, 1].withEagerDefault{ 42 }
           assert list[0] == 0
           assert list[1] == 1
           assert list[3] == 42   // default value
           assert list == [0, 1, 42, 42]   // gap filled with default value

           // illustrate using the index when generating default values
           def list2 = [5].withEagerDefault{ index -> index * index }
           assert list2[3] == 9
           assert list2 == [5, 1, 4, 9]

           // illustrate what happens with null values
           list2[2] = null
           assert list2[2] == null
           assert list2 == [5, 1, null, 9]

      Parameters:
        `init` - a Closure with the target index as parameter which generates the default value
      Returns:
        the wrapped List
      Since:
        1.8.7

    - #### <T> public ListWithDefault<T> withLazyDefault(Closure<T> init)

      Decorates a list allowing it to grow when called with a non-existent index value. When called with such values, the list is grown in size and a default value is placed in the list by calling a supplied `init` Closure. Subsequent retrieval operations if finding a null value in the list assume it was set as null from an earlier growing operation and again call the `init` Closure to populate the retrieved value; consequently the list can't be used to store null values.

      How it works: The decorated list intercepts all calls to `getAt(index)` and `get(index)`. If an index greater than or equal to the current `size()` is used, the list will grow automatically up to the specified index. Gaps will be filled by `null`. If a default value should also be used to fill gaps instead of `null`, use `withEagerDefault`. If `getAt(index)` or `get(index)` are called and a null value is found, it is assumed that the null value was a consequence of an earlier grow list operation and the `init` Closure is called to populate the value.

      Example usage:

           def list = [0, 1].withLazyDefault{ 42 }
           assert list[0] == 0
           assert list[1] == 1
           assert list[3] == 42   // default value
           assert list == [0, 1, null, 42] // gap filled with null

           // illustrate using the index when generating default values
           def list2 = [5].withLazyDefault{ index -> index * index }
           assert list2[3] == 9
           assert list2 == [5, null, null, 9]
           assert list2[2] == 4
           assert list2 == [5, null, 4, 9]

           // illustrate what happens with null values
           list2[2] = null
           assert list2[2] == 4

      Parameters:
        `init` - a Closure with the target index as parameter which generates the default value
      Returns:
        the decorated List
      Since:
        1.8.7