Return type  Name and parameters 

boolean

any(Closure predicate)
Iterates over the contents of an int Array, and checks whether a predicate is valid for at least one element. 
boolean

asBoolean()
Coerces an int array to a boolean value. 
BigDecimal

average()
Calculates the average of the ints in the array. 
List

chop(int chopSizes)
Chops the int 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. 
int[]

each(IntConsumer consumer)
Iterates through an int[] passing each int to the given consumer. 
int[]

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

equals(int[] right)
Compares the contents of this array to the contents of the given array. 
boolean

every(Closure predicate)
Iterates over the contents of an int Array, and checks whether a predicate is valid for all elements. 
int

first()
Returns the first item from the int array. 
List

flatten()
Flattens an array. 
List

getAt(IntRange range)
Supports the subscript operator for an int array with an IntRange giving the desired indices. 
List

getAt(ObjectRange range)
Supports the subscript operator for an int array with an ObjectRange giving the desired indices. 
List

getAt(Range range)
Supports the subscript operator for an int array with a range giving the desired indices. 
List

getAt(Collection indices)
Supports the subscript operator for an int array with a (potentially nested) collection giving the desired indices. 
IntRange

getIndices()
Returns indices of the int array. 
int

head()
Returns the first item from the int array. 
Map

indexed()
Zips an int[] with indices in (index, value) order starting from index 0. 
Map

indexed(int offset)
Zips an int[] with indices in (index, value) order. 
int[]

init()
Returns the items from the int array excluding the last item. 
IntStream

intStream()
Returns a sequential IntStream with the specified array as its source. 
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. 
int

last()
Returns the last item from the int array. 
int

max()
Adds max() method to int arrays. 
int

max(IntComparator comparator)
Selects the maximum value found from the int array using the supplier IntBinaryOperator as a comparator to determine the maximum of any two values. 
int

max(IntUnaryOperator operator)
Selects the maximum value found from the int array using the supplier IntUnaryOperator to determine the maximum of any two values. 
int

maxBy(Closure closure)
Selects the maximum value found from the int array using the closure to determine the maximum of any two values. 
int

maxComparing(Comparator comparator)
Selects the maximum value found from the int array using the comparator to determine the maximum of any two values. 
int

min()
Adds min() method to int arrays. 
int

min(IntComparator comparator)
Selects the minimum value found from the int array using the supplier IntComparator to determine the minimum of any two values. 
int

min(IntUnaryOperator operator)
Selects the minimum value found from the int array using the supplier IntUnaryOperator to determine the minimum of any two values. 
int

minBy(Closure closure)
Selects the minimum value found from the int array using the closure to determine the minimum of any two values. 
int

minComparing(Comparator comparator)
Selects the minimum value found from the int array using the comparator to determine the minimum of any two values. 
int[]

reverse()
Creates a new int array containing items which are the same as this array but in reverse order. 
int[]

reverse(boolean mutate)
Reverses the items in an array. 
int[]

reverseEach(Closure closure)
Iterates through an int[] in reverse order passing each int 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. 
int

sum()
Sums the items in an array. 
int

sum(int initialValue)
Sums the items in an array, adding the result to some initial value. 
int[]

swap(int i, int j)
Swaps two elements at the specified positions. 
int[]

tail()
Returns the items from the int 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. 
Iterates over the contents of an int Array, and checks whether a predicate is valid for at least one element.
int[] array = [0, 1, 2] assert array.any{ it > 1 } assert !array.any{ it > 3 }
predicate
 the closure predicate used for matchingCoerces an int array to a boolean value. An int array is false if the array is of length 0, and true otherwise.
Calculates the average of the ints in the array.
assert 5.0G == ([2,4,6,8] as int[]).average()
Chops the int 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.
int[] array = [0, 1, 2] assert array.chop(1, 2) == [[0], [1, 2]]
chopSizes
 the sizes for the returned piecesChecks whether the array contains the given value.
value
 the value being searched forCounts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0
).
int[] array = [10, 20, 20, 30] assert array.count(20) == 2
value
 the value being searched forIterates through an int[] passing each int to the given consumer.
int[] array = [0, 1, 2] String result = '' array.each{ result += it } assert result == '012'
consumer
 the consumer for each intIterates through an int[], passing each int and the element's index (a counter starting at zero) to the given closure.
int[] array = [10, 20, 30]
String result = ''
array.eachWithIndex{ item, index >
result += "$index($item)" }
assert result == '0(10)1(20)2(30)'
closure
 a Closure to operate on each intCompares the contents of this array to the contents of the given array.
Example usage:
int[] array1 = [4, 8] int[] array2 = [4, 8] assert array1 !== array2 assert array1.equals(array2)
right
 the array being comparedIterates over the contents of an int Array, and checks whether a predicate is valid for all elements.
int[] array = [0, 1, 2] assert array.every{ it < 3 } assert !array.every{ it > 1 }
predicate
 the closure predicate used for matchingReturns the first item from the int array.
int[] ints = [1, 3, 5] assert ints.first() == 1An alias for
head()
.
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 nonarrays where flattening would be applicable.
int[] array = [0, 1] assert array.flatten() == [0, 1]
Supports the subscript operator for an int array with an IntRange giving the desired indices.
int[] array = [0, 10, 20, 30, 40] assert array[2..3] == [20, 30] assert array[2..1] == [30, 40] assert array[1..2] == [40, 30]
range
 an IntRange indicating the indices for the items to retrieveSupports the subscript operator for an int array with an ObjectRange giving the desired indices.
int[] array = [0, 10, 20, 30, 40] def range = new ObjectRange(2, 3) assert array[range] == [20, 30]
range
 an ObjectRange indicating the indices for the items to retrieveSupports the subscript operator for an int array with a range giving the desired indices.
int[] array = [1, 3, 5, 7, 9, 11] assert array[2..<2] == [] // EmptyRange assert array[(0..5.5).step(2)] == [1, 5, 9] // NumberRange assert array[(1..5.5).step(2)] == [3, 7, 11] // NumberRange
range
 a range indicating the indices for the items to retrieveSupports the subscript operator for an int array with a (potentially nested) collection giving the desired indices.
int[] array = [0, 2, 4, 6, 8] assert array[2, 3] == [4, 6] assert array[1, 0..1, [0, [1]]] == [2, 0, 2, 0, 8]
indices
 a collection of indices for the items to retrieveReturns indices of the int array.
int[] array = [0, 1] assert array.indices == 0..1
Returns the first item from the int array.
int[] ints = [1, 3, 5] assert ints.head() == 1An alias for
first()
.
Zips an int[] with indices in (index, value) order starting from index 0.
Example usage:
int[] nums = [10, 20, 30] assert [0: 10, 1: 20, 2: 30] == nums.indexed()
Zips an int[] with indices in (index, value) order.
Example usage:
int[] nums = [10, 20, 30]
assert [5: 10, 6: 20, 7: 30] == nums.indexed(5)
assert ["1: 10", "2: 20", "3: 30"] == nums.indexed(1).collect { idx, str >
"$idx: $str" }
offset
 an index to start fromReturns the items from the int array excluding the last item.
int[] ints = [1, 3, 5] def result = ints.init() assert result == [1, 3] assert ints.class.componentType == result.class.componentType
Returns a sequential IntStream with the specified array as its source.
Stream
for the arrayConcatenates the string representation of each item in this array.
Concatenates the string representation of each item in this array, with the given String as a separator between each item.
separator
 a String separatorReturns the last item from the int array.
int[] ints = [1, 3, 5] assert ints.last() == 5
Adds max() method to int arrays.
Example usage:
int[] nums = [1, 3, 2] assert 3 == nums.max()
Selects the maximum value found from the int array using the supplier IntBinaryOperator as a comparator to determine the maximum of any two values.
int[] nums = [10, 20, 30] assert 20 == nums.max{ n, m>
n<=>
m } assert 30 == nums.max{ n, m>
n.abs()<=>
m.abs() }
comparator
 a comparator, i.e. returns a negative value if the first parameter is less than the secondSelects the maximum value found from the int array using the supplier IntUnaryOperator to determine the maximum of any two values. The operator is applied to each array element and the results are compared.
int[] nums = [10, 20, 30] assert 20 == nums.max{ it } assert 30 == nums.max{ it.abs() }
operator
 an operator that returns an int used for comparing valuesSelects the maximum value found from the int array using the closure to determine the maximum of any two values.
int[] nums = [30, 45, 60, 90] assert 90 == nums.maxBy{ Math.sin(Math.toRadians(it)) } assert 30 == nums.maxBy{ Math.cos(Math.toRadians(it)) } // cos(90) == 0
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.
closure
 a Closure used to determine the correct orderingSelects the maximum value found from the int array using the comparator to determine the maximum of any two values.
int[] nums = [10, 20, 30] assert 30 == nums.maxComparing(Comparator.naturalOrder()) assert 10 == nums.maxComparing(Comparator.reverseOrder())
comparator
 a ComparatorAdds min() method to int arrays.
Example usage:
int[] nums = [20, 10, 30] assert 10 == nums.min()
Selects the minimum value found from the int array using the supplier IntComparator to determine the minimum of any two values.
int[] nums = [10, 20, 30] assert 20 == nums.min{ n, m>
n<=>
m } assert 10 == nums.min{ n, m>
n.abs()<=>
m.abs() }
comparator
 a comparator, i.e. returns a negative value if the first parameter is less than the secondSelects the minimum value found from the int array using the supplier IntUnaryOperator to determine the minimum of any two values. The operator is applied to each array element and the results are compared.
int[] nums = [10, 20, 30] assert 20L == nums.min{ n>
n } assert 10L == nums.min{ n>
n.abs() }
operator
 an operator that returns an int used for comparing valuesSelects the minimum value found from the int array using the closure to determine the minimum of any two values.
int[] nums = [20, 10, 30] assert 20 == nums.minBy{ a, b>
a<=>
b } assert 10 == 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 Integer) which is then used for further comparison.
closure
 a Closure used to determine the correct orderingSelects the minimum value found from the int array using the comparator to determine the minimum of any two values.
int[] nums = [1, 2, 3] assert 1 == nums.minComparing(Comparator.naturalOrder()) assert 3 == nums.minComparing(Comparator.reverseOrder())
comparator
 a ComparatorCreates a new int array containing items which are the same as this array but in reverse order.
int[] array = 1..2 assert array.reverse() == 2..1
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.
int[] array = 1..3 def yarra = array.reverse(true) assert array == 3..1 assert yarra == 3..1 assert array === yarra yarra = array.reverse(false) assert array !== yarra assert array == 3..1 assert yarra == 1..3
mutate
 true
if the array itself should be reversed in place, false
if a new array should be createdIterates through an int[] in reverse order passing each int to the given closure.
int[] array = [0, 1, 2] String result = '' array.reverseEach{ result += it } assert result == '210'
closure
 the closure applied on each intProvides arrays with a size
method similar to collections.
Returns a sequential Stream with the specified array as its source.
Stream
for the arraySums the items in an array.
assert 1+2+3+4 == ([1,2,3,4] as int[]).sum()
Sums the items in an array, adding the result to some initial value.
assert 5+1+2+3+4 == ([1,2,3,4] as int[]).sum(5)
initialValue
 the items in the array will be summed to this initial valueSwaps two elements at the specified positions.
Example:
assert ([1, 3, 2, 4] as int[]) == ([1, 2, 3, 4] as int[]).swap(1, 2)
i
 a positionj
 a positionReturns the items from the int array excluding the first item.
int[] ints = [1, 3, 5] def result = ints.tail() assert result == [3, 5] assert ints.class.componentType == result.class.componentType
Converts this array to a List of the same size, with each element added to the list.
Converts this array to a Set, with each unique element added to the set.
int[] array = [1, 2, 3, 2, 1] Set expected = [1, 2, 3] assert array.toSet() == expected
Returns the string representation of the given array.
int[] array = [1, 2, 3, 2, 1] assert array.toString() == '[1, 2, 3, 2, 1]'