Package:

## Class long[]

- - ### Methods Summary

    Methods
    Return type | Name and parameters
    --- | ---
    `boolean` | `any(Closure predicate)` Iterates over the contents of a long Array, and checks whether a predicate is valid for at least one element.
    `boolean` | `asBoolean()` Coerces a long array to a boolean value.
    `BigDecimal` | `average()` Calculates the average of the longs in the array.
    `List` | `chop(int chopSizes)` Chops the long array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    `boolean` | `contains(Object value)` Checks whether the array contains the given value.
    `Number` | `count(Object value)` Counts the number of occurrences of the given value inside this array.
    `long[]` | `each(LongConsumer consumer)` Iterates through a long[] passing each long to the given consumer.
    `long[]` | `eachWithIndex(Closure closure)` Iterates through a long[], passing each long and the element's index (a counter starting at zero) to the given closure.
    `boolean` | `equals(long[] right)` Compares the contents of this array to the contents of the given array.
    `boolean` | `every(Closure predicate)` Iterates over the contents of a long Array, and checks whether a predicate is valid for all elements.
    `long` | `first()` Returns the first item from the long array.
    `List` | `flatten()` Flattens an array.
    `List` | `getAt(IntRange range)` Supports the subscript operator for a long array with an IntRange giving the desired indices.
    `List` | `getAt(ObjectRange range)` Supports the subscript operator for a long array with an ObjectRange giving the desired indices.
    `List` | `getAt(Range range)` Supports the subscript operator for a long array with a range giving the desired indices.
    `List` | `getAt(Collection indices)` Supports the subscript operator for a long array with a (potentially nested) collection giving the desired indices.
    `IntRange` | `getIndices()` Returns indices of the long array.
    `long` | `head()` Returns the first item from the long array.
    `Map` | `indexed()` Zips a long[] with indices in (index, value) order starting from index 0.
    `Map` | `indexed(int offset)` Zips a long[] with indices in (index, value) order.
    `long[]` | `init()` Returns the items from the long array excluding the last item.
    `String` | `join()` Concatenates the string representation of each item in this array.
    `String` | `join(String separator)` Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    `long` | `last()` Returns the last item from the long array.
    `LongStream` | `longStream()` Returns a sequential LongStream with the specified array as its source.
    `long` | `max()` Adds max() method to long arrays.
    `long` | `max(LongComparator comparator)` Selects the maximum value found from the long array using the supplier LongBinaryOperator as a comparator to determine the maximum of any two values.
    `long` | `max(LongUnaryOperator operator)` Selects the maximum value found from the long array using the supplier LongUnaryOperator to determine the maximum of any two values.
    `long` | `maxBy(Closure closure)` Selects the maximum value found from the long array using the closure to determine the maximum of any two values.
    `long` | `maxComparing(Comparator comparator)` Selects the maximum value found from the long array using the comparator to determine the maximum of any two values.
    `long` | `min()` Adds min() method to long arrays.
    `long` | `min(LongComparator comparator)` Selects the minimum value found from the long array using the supplier LongBinaryOperator as a comparator to determine the minimum of any two values.
    `long` | `min(LongUnaryOperator operator)` Selects the minimum value found from the long array using the supplier LongUnaryOperator to determine the minimum of any two values.
    `long` | `minBy(Closure closure)` Selects the minimum value found from the long array using the closure to determine the minimum of any two values.
    `long` | `minComparing(Comparator comparator)` Selects the minimum value found from the long array using the comparator to determine the minimum of any two values.
    `long[]` | `reverse()` Creates a new long array containing items which are the same as this array but in reverse order.
    `long[]` | `reverse(boolean mutate)` Reverses the items in an array.
    `long[]` | `reverseEach(Closure closure)` Iterates through a long[] in reverse order passing each long to the given closure.
    `int` | `size()` Provides arrays with a `size` method similar to collections.
    `Stream` | `stream()` Returns a sequential Stream with the specified array as its source.
    `long` | `sum()` Sums the items in an array.
    `long` | `sum(long initialValue)` Sums the items in an array, adding the result to some initial value.
    `long[]` | `swap(int i, int j)` Swaps two elements at the specified positions.
    `long[]` | `tail()` Returns the items from the long array excluding the first item.
    `List` | `toList()` Converts this array to a List of the same size, with each element added to the list.
    `Set` | `toSet()` Converts this array to a Set, with each unique element added to the set.
    `String` | `toString()` Returns the string representation of the given array.

- - ### Methods Detail

    - #### public boolean any(Closure predicate)

      Iterates over the contents of a long Array, and checks whether a predicate is valid for at least one element.

          long[] array = [0L, 1L, 2L]
          assert array.any{ it > 1L }
          assert !array.any{ it > 3L }

      Parameters:
        `predicate` - the closure predicate used for matching
      Returns:
        true if any iteration for the longs matches the closure predicate
      Since:
        5.0.0

    - #### public boolean asBoolean()

      Coerces a long array to a boolean value. A long array is false if the array is of length 0, and true otherwise.

      Returns:
        the array's boolean value
      Since:
        1.7.4

    - #### public BigDecimal average()

      Calculates the average of the longs in the array.

          assert 5.0G == ([2,4,6,8] as long[]).average()

      Returns:
        The average of the items
      Since:
        3.0.0

    - #### public List chop(int chopSizes)

      Chops the long array into pieces, returning lists with sizes corresponding to the supplied chop sizes. If the array isn't large enough, truncated (possibly empty) pieces are returned. Using a chop size of -1 will cause that piece to contain all remaining items from the array.

          long[] array = [0, 1, 2]
          assert array.chop(1, 2) == [[0], [1, 2]]

      Parameters:
        `chopSizes` - the sizes for the returned pieces
      Returns:
        a list of lists chopping the original array elements into pieces determined by chopSizes
      Since:
        5.0.0
      See Also:
        DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size

    - #### public boolean contains(Object value)

      Checks whether the array contains the given value.

      Parameters:
        `value` - the value being searched for
      Returns:
        true if the array contains the value
      Since:
        1.8.6

    - #### public Number count(Object value)

      Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using `compareTo(value) == 0`).

          long[] array = [10L, 20L, 20L, 30L]
          assert array.count(20L) == 2

      Parameters:
        `value` - the value being searched for
      Returns:
        the number of occurrences
      Since:
        1.6.4
      See Also:
        DefaultGroovyMethods#count(Iterator, Object)

    - #### public long[] each(LongConsumer consumer)

      Iterates through a long[] passing each long to the given consumer.

          long[] array = [0L, 1L, 2L]
          String result = ''
          array.each{ result += it }
          assert result == '012'

      Parameters:
        `consumer` - the consumer for each long
      Returns:
        the self array
      Since:
        5.0.0

    - #### public long[] eachWithIndex(Closure closure)

      Iterates through a long[], passing each long and the element's index (a counter starting at zero) to the given closure.

          long[] array = [10L, 20L, 30L]
          String result = ''
          array.eachWithIndex{ item, index -> result += "$index($item)" }
          assert result == '0(10)1(20)2(30)'

      Parameters:
        `closure` - a Closure to operate on each long
      Returns:
        the self array
      Since:
        5.0.0

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

      Compares the contents of this array to the contents of the given array.

      Example usage:

          long[] array1 = [4L, 8L]
          long[] array2 = [4L, 8L]
          assert array1 !== array2
          assert array1.equals(array2)

      Parameters:
        `right` - the array being compared
      Returns:
        true if the contents of both arrays are equal.
      Since:
        5.0.0

    - #### public boolean every(Closure predicate)

      Iterates over the contents of a long Array, and checks whether a predicate is valid for all elements.

          long[] array = [0L, 1L, 2L]
          assert array.every{ it < 3L }
          assert !array.every{ it > 1L }

      Parameters:
        `predicate` - the closure predicate used for matching
      Returns:
        true if the predicate returns true for all elements in the array
      Since:
        5.0.0

    - #### public long first()

      Returns the first item from the long array.

          long[] longs = [2L, 4L, 6L]
          assert longs.first() == 2L

      An alias for `head()`.
      Returns:
        the first element
      Since:
        5.0.0

    - #### public List flatten()

      Flattens an array. This array is added to a new collection. It is an alias for `toList()` but allows algorithms to be written which also work on multidimensional arrays or non-arrays where flattening would be applicable.

          long[] array = [0L, 1L]
          assert array.flatten() == [0L, 1L]

      Returns:
        a Collection of the array elements
      Since:
        1.6.0

    - #### public List getAt(IntRange range)

      Supports the subscript operator for a long array with an IntRange giving the desired indices.

          long[] array = [0L, 10L, 20L, 30L, 40L]
          assert array[2..3] == [20L, 30L]
          assert array[-2..-1] == [30L, 40L]
          assert array[-1..-2] == [40L, 30L]

      Parameters:
        `range` - an IntRange indicating the indices for the items to retrieve
      Returns:
        list of the retrieved longs
      Since:
        1.0

    - #### public List getAt(ObjectRange range)

      Supports the subscript operator for a long array with an ObjectRange giving the desired indices.

          long[] array = [0L, 10L, 20L, 30L, 40L]
          def range = new ObjectRange(2, 3)
          assert array[range] == [20L, 30L]

      Parameters:
        `range` - an ObjectRange indicating the indices for the items to retrieve
      Returns:
        list of the retrieved longs
      Since:
        1.0

    - #### public List getAt(Range range)

      Supports the subscript operator for a long array with a range giving the desired indices.

          long[] array = [1L, 3L, 5L, 7L, 9L, 11L]
          assert array[2..<2] == [] // EmptyRange
          assert array[(0..5.5).step(2)] == [1L, 5L, 9L]   // NumberRange
          assert array[(1..5.5).step(2)] == [3L, 7L, 11L]  // NumberRange

      Parameters:
        `range` - a range indicating the indices for the items to retrieve
      Returns:
        list of the retrieved longs
      Since:
        1.0

    - #### public List getAt(Collection indices)

      Supports the subscript operator for a long array with a (potentially nested) collection giving the desired indices.

          long[] array = [0L, 2L, 4L, 6L, 8L]
          assert array[2, 3] == [4L, 6L]
          assert array[1, 0..1, [0, [-1]]] == [2L, 0L, 2L, 0L, 8L]

      Parameters:
        `indices` - a collection of indices for the items to retrieve
      Returns:
        list of the longs at the given indices
      Since:
        1.0

    - #### public IntRange getIndices()

      Returns indices of the long array.

          long[] array = [0L, 1L]
          assert array.indices == 0..1

      Since:
        3.0.8
      See Also:
        DefaultGroovyMethods#getIndices(Object[])

    - #### public long head()

      Returns the first item from the long array.

          long[] longs = [2L, 4L, 6L]
          assert longs.head() == 2L

      An alias for `first()`.
      Returns:
        the first element
      Since:
        5.0.0

    - #### public Map indexed()

      Zips a long[] with indices in (index, value) order starting from index 0.

      Example usage:

          long[] nums = [10L, 20L, 30L]
          assert [0: 10L, 1: 20L, 2: 30L] == nums.indexed()

      Since:
        3.0.8
      See Also:
        long[]#indexed(int)

    - #### public Map indexed(int offset)

      Zips a long[] with indices in (index, value) order.

      Example usage:

          long[] nums = [10L, 20L, 30L]
          assert [5: 10L, 6: 20L, 7: 30L] == nums.indexed(5)

      Parameters:
        `offset` - an index to start from
      Returns:
        a Map (since the keys/indices are unique) containing the elements from the iterable zipped with indices
      Since:
        3.0.8
      See Also:
        DefaultGroovyMethods#indexed(Iterable, int)

    - #### public long[] init()

      Returns the items from the long array excluding the last item.

          long[] longs = [2L, 4L, 6L]
          def result = longs.init()
          assert result == [2L, 4L]
          assert longs.class.componentType == result.class.componentType

      Returns:
        an array without its last element
      Since:
        5.0.0

    - #### public String join()

      Concatenates the string representation of each item in this array.

      Returns:
        the joined String
      Since:
        5.0.0

    - #### public String join(String separator)

      Concatenates the string representation of each item in this array, with the given String as a separator between each item.

      Parameters:
        `separator` - a String separator
      Returns:
        the joined String
      Since:
        2.4.1

    - #### public long last()

      Returns the last item from the long array.

          long[] longs = [2L, 4L, 6L]
          assert longs.last() == 6L

      Returns:
        the last element
      Since:
        5.0.0

    - #### public LongStream longStream()

      Returns a sequential LongStream with the specified array as its source.

      Returns:
        a `Stream` for the array
      Since:
        3.0.8

    - #### public long max()

      Adds max() method to long arrays.

      Example usage:

          long[] nums = [1L, 3L, 2L]
          assert 3L == nums.max()

      Returns:
        the maximum value
      Since:
        3.0.8

    - #### public long max(LongComparator comparator)

      Selects the maximum value found from the long array using the supplier LongBinaryOperator as a comparator to determine the maximum of any two values.

          long[] nums = [10L, 20L, -30L]
          assert 20L == nums.max{ n, m -> n <=> m }
          assert -30L == nums.max{ n, m -> n.abs() <=> m.abs() }

      Parameters:
        `comparator` - a comparator, i.e. returns a negative value if the first parameter is less than the second
      Returns:
        the maximum value
      Since:
        5.0.0

    - #### public long max(LongUnaryOperator operator)

      Selects the maximum value found from the long array using the supplier LongUnaryOperator to determine the maximum of any two values. The operator is applied to each array element and the results are compared.

          long[] nums = [10L, 20L, -30L]
          assert 20L == nums.max{ it }
          assert -30L == nums.max{ it.abs() }

      Parameters:
        `operator` - an operator that returns a long used for comparing values
      Returns:
        the maximum value
      Since:
        5.0.0

    - #### public long maxBy(Closure closure)

      Selects the maximum value found from the long array using the closure to determine the maximum of any two values.

          long[] nums = [-30L, 10L, 20L]
          assert 20L == nums.maxBy{ a, b -> a <=> b }
          assert -30L == nums.maxBy{ it.abs() }

      If the closure has two parameters it is used like a traditional Comparator, i.e., it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an Integer) which is then used for further comparison.

      Parameters:
        `closure` - a Closure used to determine the correct ordering
      Returns:
        the maximum value
      Since:
        5.0.0
      See Also:
        DefaultGroovyMethods#max(Iterator, groovy.lang.Closure)

    - #### public long maxComparing(Comparator comparator)

      Selects the maximum value found from the long array using the comparator to determine the maximum of any two values.

          long[] nums = [10L, 20L, 30L]
          assert 30L == nums.maxComparing(Comparator.naturalOrder())
          assert 10L == nums.maxComparing(Comparator.reverseOrder())

      Parameters:
        `comparator` - a Comparator
      Returns:
        the maximum value
      Since:
        5.0.0
      See Also:
        DefaultGroovyMethods#max(Iterator, java.util.Comparator)

    - #### public long min()

      Adds min() method to long arrays.

      Example usage:

          long[] nums = [20L, 10L, 30L]
          assert 10L == nums.min()

      Returns:
        the minimum value
      Since:
        3.0.8

    - #### public long min(LongComparator comparator)

      Selects the minimum value found from the long array using the supplier LongBinaryOperator as a comparator to determine the minimum of any two values.

          long[] nums = [10L, -20L, 30L]
          assert -20L == nums.min{ n, m -> n <=> m }
          assert 10L == nums.min{ n, m -> n.abs() <=> m.abs() }

      Parameters:
        `comparator` - a comparator, i.e. returns a negative value if the first parameter is less than the second
      Returns:
        the minimum value
      Since:
        5.0.0

    - #### public long min(LongUnaryOperator operator)

      Selects the minimum value found from the long array using the supplier LongUnaryOperator to determine the minimum of any two values. The operator is applied to each array element and the results are compared.

          long[] nums = [10L, -20L, 30L]
          assert -20L == nums.min{ it }
          assert 10L == nums.min{ it.abs() }

      Parameters:
        `operator` - an operator that returns a long used for comparing values
      Returns:
        the minimum value
      Since:
        5.0.0

    - #### public long minBy(Closure closure)

      Selects the minimum value found from the long array using the closure to determine the minimum of any two values.

          long[] nums = [-20L, 10L, 30L]
          assert -20L == nums.minBy{ a, b -> a <=> b }
          assert 10L == nums.minBy{ it.abs() }

      If the closure has two parameters it is used like a traditional Comparator, i.e., it should compare its two parameters for order, returning a negative integer, zero, or a positive integer when the first parameter is less than, equal to, or greater than the second respectively. Otherwise, the Closure is assumed to take a single parameter and return a Comparable (typically an int or long) which is then used for further comparison.

      Parameters:
        `closure` - a Closure used to determine the correct ordering
      Returns:
        the minimum value
      Since:
        5.0.0
      See Also:
        DefaultGroovyMethods#min(Iterator, groovy.lang.Closure)

    - #### public long minComparing(Comparator comparator)

      Selects the minimum value found from the long array using the comparator to determine the minimum of any two values.

          long[] nums = [10L, 20L, 30L]
          assert 10L == nums.minComparing(Comparator.naturalOrder())
          assert 30L == nums.minComparing(Comparator.reverseOrder())

      Parameters:
        `comparator` - a Comparator
      Returns:
        the minimum value
      Since:
        5.0.0
      See Also:
        DefaultGroovyMethods#min(Iterator, java.util.Comparator)

    - #### public long[] reverse()

      Creates a new long array containing items which are the same as this array but in reverse order.

          long[] array = 1L..2L
          assert array.reverse() == 2L..1L

      Returns:
        an array containing the reversed items
      Since:
        5.0.0
      See Also:
        long[]#reverse(boolean)

    - #### public long[] reverse(boolean mutate)

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

          long[] array = 1L..3L
          def yarra = array.reverse(true)
          assert array == 3L..1L
          assert yarra == 3L..1L
          assert array === yarra
          yarra = array.reverse(false)
          assert array !== yarra
          assert array == 3L..1L
          assert yarra == 1L..3L

      Parameters:
        `mutate` - `true` if the array itself should be reversed in place, `false` if a new array should be created
      Returns:
        an array containing the reversed items
      Since:
        5.0.0

    - #### public long[] reverseEach(Closure closure)

      Iterates through a long[] in reverse order passing each long to the given closure.

          long[] array = [0, 1, 2]
          String result = ''
          array.reverseEach{ result += it }
          assert result == '210'

      Parameters:
        `closure` - the closure applied on each long
      Returns:
        the self array
      Since:
        5.0.0

    - #### public int size()

      Provides arrays with a `size` method similar to collections.

      Returns:
        the length of the array
      Since:
        1.0

    - #### public Stream stream()

      Returns a sequential Stream with the specified array as its source.

      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public long sum()

      Sums the items in an array.

          assert (1+2+3+4 as long) == ([1,2,3,4] as long[]).sum()

      Returns:
        The sum of all the items
      Since:
        2.4.2

    - #### public long sum(long initialValue)

      Sums the items in an array, adding the result to some initial value.

          assert (5+1+2+3+4 as long) == ([1,2,3,4] as long[]).sum(5)

      Parameters:
        `initialValue` - the items in the array will be summed to this initial value
      Returns:
        The sum of all the items.
      Since:
        2.4.2

    - #### public long[] swap(int i, int j)

      Swaps two elements at the specified positions.

      Example:

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

      Parameters:
        `i` - a position
        `j` - a position
      Returns:
        self
      Since:
        2.4.0

    - #### public long[] tail()

      Returns the items from the long array excluding the first item.

          long[] longs = [2L, 4L, 6L]
          def result = longs.tail()
          assert result == [4L, 6L]
          assert longs.class.componentType == result.class.componentType

      Returns:
        an array without its first element
      Since:
        5.0.0

    - #### public List toList()

      Converts this array to a List of the same size, with each element added to the list.

      Returns:
        A list containing the contents of this array.
      Since:
        1.0

    - #### public Set toSet()

      Converts this array to a Set, with each unique element added to the set.

          long[] array = [1, 2, 3, 2, 1]
          Set expected = [1, 2, 3]
          assert array.toSet() == expected

      Returns:
        A set containing the unique contents of this array.
      Since:
        1.8.0

    - #### public String toString()

      Returns the string representation of the given array.

          long[] array = [1, 2, 3, 2, 1]
          assert array.toString() == '[1, 2, 3, 2, 1]'

      Returns:
        the string representation
      Since:
        1.6.0