Class ArrayGroovyMethods

java.lang.Object
org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
org.codehaus.groovy.runtime.ArrayGroovyMethods

public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport
This class defines new groovy methods which appear on primitive arrays inside the Groovy environment. Static methods are used with the first parameter being the destination class, i.e. public static int[] each(int[] self, Closure closure) provides a each({i -> }) method for int[].

NOTE: While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    any(boolean[] self)
    Iterates over the contents of a boolean Array, and checks whether any element is true.
    static boolean
    any(boolean[] self, Closure<?> predicate)
    Iterates over the contents of a boolean Array, and checks whether a predicate is valid for at least one element.
    static boolean
    any(byte[] self, Closure<?> predicate)
    Iterates over the contents of a byte Array, and checks whether a predicate is valid for at least one element.
    static boolean
    any(char[] self, Closure<?> predicate)
    Iterates over the contents of a char Array, and checks whether a predicate is valid for at least one element.
    static boolean
    any(double[] self, Closure<?> predicate)
    Iterates over the contents of a double Array, and checks whether a predicate is valid for at least one element.
    static boolean
    any(float[] self, Closure<?> predicate)
    Iterates over the contents of a float Array, and checks whether a predicate is valid for at least one element.
    static boolean
    any(int[] self, Closure<?> predicate)
    Iterates over the contents of an int Array, and checks whether a predicate is valid for at least one element.
    static boolean
    any(long[] self, Closure<?> predicate)
    Iterates over the contents of a long Array, and checks whether a predicate is valid for at least one element.
    static boolean
    any(short[] self, Closure<?> predicate)
    Iterates over the contents of a short Array, and checks whether a predicate is valid for at least one element.
    static <T> boolean
    any(T[] self, Closure<?> predicate)
    Iterates over the contents of an Array, and checks whether a predicate is valid for at least one element.
    static boolean
    asBoolean(boolean[] self)
    Coerces a boolean array to a boolean value.
    static boolean
    asBoolean(byte[] self)
    Coerces a byte array to a boolean value.
    static boolean
    asBoolean(char[] self)
    Coerces a char array to a boolean value.
    static boolean
    asBoolean(double[] self)
    Coerces a double array to a boolean value.
    static boolean
    asBoolean(float[] self)
    Coerces a float array to a boolean value.
    static boolean
    asBoolean(int[] self)
    Coerces an int array to a boolean value.
    static boolean
    asBoolean(long[] self)
    Coerces a long array to a boolean value.
    static boolean
    asBoolean(short[] self)
    Coerces a short array to a boolean value.
    static boolean
    asBoolean(Object[] self)
    Coerces an object array to a boolean value.
    static <T> T
    asType(Object[] self, Class<T> type)
    Converts the given array to either a List, Set, or SortedSet.
    static BigDecimal
    average(byte[] self)
    Calculates the average of the bytes in the array.
    static double
    average(double[] self)
    Calculates the average of the doubles in the array.
    static double
    average(float[] self)
    Calculates the average of the floats in the array.
    static BigDecimal
    average(int[] self)
    Calculates the average of the ints in the array.
    static BigDecimal
    average(long[] self)
    Calculates the average of the longs in the array.
    static BigDecimal
    average(short[] self)
    Calculates the average of the shorts in the array.
    static Object
    average(Object[] self)
    Averages the items in an array.
    static <T> Object
    average(T[] self, Closure<?> closure)
    Averages the result of applying a closure to each item of an array.
    static List<List<Boolean>>
    chop(boolean[] self, int... chopSizes)
    Chops the boolean array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    static List<List<Byte>>
    chop(byte[] self, int... chopSizes)
    Chops the byte array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    chop(char[] self, int... chopSizes)
    Chops the char array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    static List<List<Double>>
    chop(double[] self, int... chopSizes)
    Chops the double array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    static List<List<Float>>
    chop(float[] self, int... chopSizes)
    Chops the float array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    static List<List<Integer>>
    chop(int[] self, int... chopSizes)
    Chops the int array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    static List<List<Long>>
    chop(long[] self, int... chopSizes)
    Chops the long array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    static List<List<Short>>
    chop(short[] self, int... chopSizes)
    Chops the short array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    static <T> List<List<T>>
    chop(T[] self, int... chopSizes)
    Chops the array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    static <T> List<List<T>>
    collate(T[] self, int size)
    Collates an array.
    static <T> List<List<T>>
    collate(T[] self, int size, boolean keepRemainder)
    Collates this array into sub-lists.
    static <T> List<List<T>>
    collate(T[] self, int size, int step)
    Collates an array into sub-lists.
    static <T> List<List<T>>
    collate(T[] self, int size, int step, boolean keepRemainder)
    Collates this array into sub-lists.
    static <E, T, C extends Collection<T>>
    C
    collect(E[] self, C collector, Closure<? extends T> transform)
    Iterates through this Array transforming each item into a new value using the transform closure and adding it to the supplied collector.
    static <E, T> List<T>
    collect(E[] self, Closure<T> transform)
    Iterates through this Array transforming each item into a new value using the transform closure, returning a list of transformed values.
    static <K, V, E> Map<K,V>
    collectEntries(E[] self)
    A variant of collectEntries using the identity closure as the transform.
    static <K, V, E> Map<K,V>
    collectEntries(E[] self, Closure<?> transform)
    Iterates through this array transforming each item using the transform closure and returning a map of the resulting transformed entries.
    static <K, V, E> Map<K,V>
    collectEntries(E[] self, Function<? super E,K> keyTransform, Function<? super E,V> valueTransform)
    A variant of collectEntries for arrays with separate functions for transforming the keys and values.
    static <K, V, E> Map<K,V>
    collectEntries(E[] self, Map<K,V> collector)
    A variant of collectEntries using the identity closure as the transform.
    static <K, V, E> Map<K,V>
    collectEntries(E[] self, Map<K,V> collector, Closure<?> transform)
    Iterates through this array transforming each item using the transform closure and returning a map of the resulting transformed entries.
    static <K, V, E> Map<K,V>
    collectEntries(E[] self, Map<K,V> collector, Function<? super E,K> keyTransform, Function<? super E,V> valueTransform)
    A variant of collectEntries for arrays with separate functions for transforming the keys and values.
    static <T, E, C extends Collection<T>>
    C
    collectMany(E[] self, C collector, Closure<? extends Collection<? extends T>> projection)
    Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.
    static <T, E> List<T>
    collectMany(E[] self, Closure<? extends Collection<? extends T>> projection)
    Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.
    static boolean
    contains(boolean[] self, Object value)
    Checks whether the array contains the given value.
    static boolean
    contains(byte[] self, Object value)
    Checks whether the array contains the given value.
    static boolean
    contains(char[] self, Object value)
    Checks whether the array contains the given value.
    static boolean
    contains(double[] self, Object value)
    Checks whether the array contains the given value.
    static boolean
    contains(float[] self, Object value)
    Checks whether the array contains the given value.
    static boolean
    contains(int[] self, Object value)
    Checks whether the array contains the given value.
    static boolean
    contains(long[] self, Object value)
    Checks whether the array contains the given value.
    static boolean
    contains(short[] self, Object value)
    Checks whether the array contains the given value.
    static boolean
    contains(Object[] self, Object value)
    Checks whether the array contains the given value.
    static Number
    count(boolean[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static Number
    count(byte[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static Number
    count(char[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static Number
    count(double[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static Number
    count(float[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static Number
    count(int[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static Number
    count(long[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static Number
    count(short[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static Number
    count(Object[] self, Object value)
    Counts the number of occurrences of the given value inside this array.
    static <T> Number
    count(T[] self, Closure<?> predicate)
    Counts the number of occurrences which satisfy the given closure from inside this array.
    static <K, E> Map<K,Integer>
    countBy(E[] self, Closure<K> closure)
    Sorts all array members into groups determined by the supplied mapping closure and counts the group size.
    static <T> T[]
    drop(T[] self, int num)
    Drops the given number of elements from the head of this array if they are available.
    static <T> T[]
    dropRight(T[] self, int num)
    Drops the given number of elements from the tail of this array if they are available.
    static <T> T[]
    dropWhile(T[] self, Closure<?> condition)
    Create a suffix of the given array by dropping as many elements as possible from the front of the original array such that calling the given closure condition evaluates to true when passed each of the dropped elements.
    static boolean[]
    each(boolean[] self, Consumer<Boolean> consumer)
    Iterates through a boolean[] passing each boolean to the given consumer.
    static byte[]
    each(byte[] self, Consumer<Byte> consumer)
    Iterates through a byte[] passing each byte to the given consumer.
    static char[]
    each(char[] self, Consumer<Character> consumer)
    Iterates through a char[] passing each char to the given consumer.
    static double[]
    each(double[] self, DoubleConsumer consumer)
    Iterates through a double[] passing each double to the given consumer.
    static float[]
    each(float[] self, Consumer<Float> consumer)
    Iterates through a float[] passing each float to the given consumer.
    static int[]
    each(int[] self, IntConsumer consumer)
    Iterates through an int[] passing each int to the given consumer.
    static long[]
    each(long[] self, LongConsumer consumer)
    Iterates through a long[] passing each long to the given consumer.
    static short[]
    each(short[] self, Consumer<Short> consumer)
    Iterates through a short[] passing each short to the given consumer.
    static <T> T[]
    each(T[] self, Closure<?> closure)
    Iterates through an array passing each array entry to the given closure.
    static void
    eachByte(byte[] self, Closure<?> closure)
    Traverses through each byte of this byte array.
    static void
    eachByte(Byte[] self, Closure<?> closure)
    Traverses through each byte of this Byte array.
    static boolean[]
    eachWithIndex(boolean[] self, Closure<?> closure)
    Iterates through a boolean[], passing each boolean and the element's index (a counter starting at zero) to the given closure.
    static byte[]
    eachWithIndex(byte[] self, Closure<?> closure)
    Iterates through a byte[], passing each byte and the element's index (a counter starting at zero) to the given closure.
    static char[]
    eachWithIndex(char[] self, Closure<?> closure)
    Iterates through a char[], passing each char and the element's index (a counter starting at zero) to the given closure.
    static double[]
    eachWithIndex(double[] self, Closure<?> closure)
    Iterates through a double[], passing each double and the element's index (a counter starting at zero) to the given closure.
    static float[]
    eachWithIndex(float[] self, Closure<?> closure)
    Iterates through a float[], passing each float and the element's index (a counter starting at zero) to the given closure.
    static int[]
    eachWithIndex(int[] self, Closure<?> closure)
    Iterates through an int[], passing each int and the element's index (a counter starting at zero) to the given closure.
    static long[]
    eachWithIndex(long[] self, Closure<?> closure)
    Iterates through a long[], passing each long and the element's index (a counter starting at zero) to the given closure.
    static short[]
    eachWithIndex(short[] self, Closure<?> closure)
    Iterates through a short[], passing each short and the element's index (a counter starting at zero) to the given closure.
    static <T> T[]
    eachWithIndex(T[] self, Closure<?> closure)
    Iterates through an array, passing each array element and the element's index (a counter starting at zero) to the given closure.
    static boolean
    equals(boolean[] self, boolean[] right)
    Compares the contents of this array to the contents of the given array.
    static boolean
    equals(byte[] self, byte[] right)
    Compares the contents of this array to the contents of the given array.
    static boolean
    equals(char[] self, char[] right)
    Compares the contents of this array to the contents of the given array.
    static boolean
    equals(double[] self, double[] right)
    Compares the contents of this array to the contents of the given array.
    static boolean
    equals(float[] self, float[] right)
    Compares the contents of this array to the contents of the given array.
    static boolean
    equals(int[] self, int[] right)
    Compares the contents of this array to the contents of the given array.
    static boolean
    equals(long[] self, long[] right)
    Compares the contents of this array to the contents of the given array.
    static boolean
    equals(short[] self, short[] right)
    Compares the contents of this array to the contents of the given array.
    static boolean
    equals(Object[] left, List<?> right)
    Determines if the contents of this array are equal to the contents of the given list, in the same order.
    static boolean
    every(boolean[] self)
    Iterates over the contents of a boolean Array, and checks whether every element is true.
    static boolean
    every(boolean[] self, Closure<?> predicate)
    Iterates over the contents of a boolean Array, and checks whether a predicate is valid for every element.
    static boolean
    every(byte[] self, Closure<?> predicate)
    Iterates over the contents of a byte Array, and checks whether a predicate is valid for all elements.
    static boolean
    every(char[] self, Closure<?> predicate)
    Iterates over the contents of a char Array, and checks whether a predicate is valid for all elements.
    static boolean
    every(double[] self, Closure<?> predicate)
    Iterates over the contents of a double Array, and checks whether a predicate is valid for all elements.
    static boolean
    every(float[] self, Closure<?> predicate)
    Iterates over the contents of a float Array, and checks whether a predicate is valid for all elements.
    static boolean
    every(int[] self, Closure<?> predicate)
    Iterates over the contents of an int Array, and checks whether a predicate is valid for all elements.
    static boolean
    every(long[] self, Closure<?> predicate)
    Iterates over the contents of a long Array, and checks whether a predicate is valid for all elements.
    static boolean
    every(short[] self, Closure<?> predicate)
    Iterates over the contents of a short Array, and checks whether a predicate is valid for all elements.
    static <T> boolean
    every(T[] self, Closure<?> predicate)
    Used to determine if the given predicate closure is valid (i.e.
    static <T> T
    find(T[] self, Closure<?> condition)
    Finds the first element in the array that matches the given closure condition.
    static <T> List<T>
    findAll(T[] self)
    Finds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth).
    static <T> List<T>
    findAll(T[] self, Closure<?> condition)
    Finds all elements of the array matching the given Closure condition.
    static <T> int
    findIndexOf(T[] self, int startIndex, Closure<?> condition)
    Iterates over the elements of an array, starting from a specified index, and returns the index of the first item that satisfies the condition specified by the closure.
    static <T> int
    findIndexOf(T[] self, Closure<?> condition)
    Iterates over the elements of an array and returns the index of the first item that satisfies the condition specified by the closure.
    static <T> List<Number>
    findIndexValues(T[] self, Closure<?> condition)
    Iterates over the elements of an array and returns the index values of the items that match the condition specified in the closure.
    static <T> List<Number>
    findIndexValues(T[] self, Number startIndex, Closure<?> condition)
    Iterates over the elements of an array, starting from a specified index, and returns the index values of the items that match the condition specified in the closure.
    static <T> int
    findLastIndexOf(T[] self, int lowerBound, Closure<?> condition)
    Returns the index of the last item that matches the specified condition that is at or beyond the given index.
    static <T> int
    findLastIndexOf(T[] self, Closure<?> condition)
    Returns the index of the last item that matches the specified condition.
    static <S, T> T
    findResult(S[] self, Closure<T> condition)
    Iterates through the Array calling the given closure condition for each item but stopping once the first non-null result is found and returning that result.
    static <S, T, U extends T, V extends T>
    T
    findResult(S[] self, U defaultResult, Closure<V> condition)
    Iterates through the Array calling the given closure condition for each item but stopping once the first non-null result is found and returning that result.
    static <T> T
    findResult(T[] self)
    Iterates through the Array stopping once the first non-null result is found and returning that result.
    static <T, U extends T, V extends T>
    T
    findResult(U[] self, V defaultResult)
    Iterates through the Array stopping once the first non-null result is found and returning that result.
    static <T> Collection<T>
    findResults(T[] self)
    Iterates through the Array collecting any non-null results.
    static <T, U> Collection<T>
    findResults(U[] self, Closure<T> filteringTransform)
    Iterates through the Array transforming items using the supplied closure and collecting any non-null results.
    static boolean
    first(boolean[] self)
    Returns the first item from the boolean array.
    static byte
    first(byte[] self)
    Returns the first item from the byte array.
    static char
    first(char[] self)
    Returns the first item from the char array.
    static double
    first(double[] self)
    Returns the first item from the double array.
    static float
    first(float[] self)
    Returns the first item from the float array.
    static int
    first(int[] self)
    Returns the first item from the int array.
    static long
    first(long[] self)
    Returns the first item from the long array.
    static short
    first(short[] self)
    Returns the first item from the short array.
    static <T> T
    first(T[] self)
    Returns the first item from the array.
    static List<Boolean>
    flatten(boolean[] self)
    Flattens an array.
    static List<Boolean>
    flatten(boolean[][] self)
    Flattens a 2D array into a new collection.
    static List<Byte>
    flatten(byte[] self)
    Flattens an array.
    static List<Byte>
    flatten(byte[][] self)
    Flattens a 2D array into a new collection.
    static List<Character>
    flatten(char[] self)
    Flattens an array.
    static List<Character>
    flatten(char[][] self)
    Flattens a 2D array into a new collection.
    static List<Double>
    flatten(double[] self)
    Flattens an array.
    static List<Double>
    flatten(double[][] self)
    Flattens a 2D array into a new collection.
    static List<Float>
    flatten(float[] self)
    Flattens an array.
    static List<Float>
    flatten(float[][] self)
    Flattens a 2D array into a new collection.
    static List<Integer>
    flatten(int[] self)
    Flattens an array.
    static List<Integer>
    flatten(int[][] self)
    Flattens a 2D array into a new collection.
    static List<Long>
    flatten(long[] self)
    Flattens an array.
    static List<Long>
    flatten(long[][] self)
    Flattens a 2D array into a new collection.
    static List<Short>
    flatten(short[] self)
    Flattens an array.
    static List<Short>
    flatten(short[][] self)
    Flattens a 2D array into a new collection.
    static List<Object>
    flatten(Object[] self)
    Flattens an array.
    static Collection
    flattenMany(Object[] self, Closure<?> transform)
    Flatten an array.
    static List<Boolean>
    getAt(boolean[] array, IntRange range)
    Supports the subscript operator for a boolean array with an IntRange giving the desired indices.
    static List<Boolean>
    getAt(boolean[] array, ObjectRange range)
    Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices.
    static List<Boolean>
    getAt(boolean[] array, Range<?> range)
    Supports the subscript operator for a boolean array with a range giving the desired indices.
    static List<Boolean>
    getAt(boolean[] array, Collection<?> indices)
    Supports the subscript operator for a boolean array with a (potentially nested) collection giving the desired indices.
    static List<Byte>
    getAt(byte[] array, IntRange range)
    Supports the subscript operator for a byte array with an IntRange giving the desired indices.
    static List<Byte>
    getAt(byte[] array, ObjectRange range)
    Supports the subscript operator for a byte array with an ObjectRange giving the desired indices.
    static List<Byte>
    getAt(byte[] array, Range<?> range)
    Supports the subscript operator for a byte array with a range giving the desired indices.
    static List<Byte>
    getAt(byte[] array, Collection<?> indices)
    Supports the subscript operator for a byte array with a (potentially nested) collection giving the desired indices.
    static List<Character>
    getAt(char[] array, IntRange range)
    Supports the subscript operator for a char array with an IntRange giving the desired indices.
    static List<Character>
    getAt(char[] array, ObjectRange range)
    Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices.
    static List<Character>
    getAt(char[] array, Range<?> range)
    Supports the subscript operator for a char array with a range giving the desired indices.
    static List<Character>
    getAt(char[] array, Collection<?> indices)
    Supports the subscript operator for a char array with a (potentially nested) collection giving the desired indices.
    static List<Double>
    getAt(double[] array, IntRange range)
    Supports the subscript operator for a double array with an IntRange giving the desired indices.
    static List<Double>
    getAt(double[] array, ObjectRange range)
    Supports the subscript operator for a double array with an ObjectRange giving the desired indices.
    static List<Double>
    getAt(double[] array, Range<?> range)
    Supports the subscript operator for a double array with a range giving the desired indices.
    static List<Double>
    getAt(double[] array, Collection<?> indices)
    Supports the subscript operator for a double array with a (potentially nested) collection giving the desired indices.
    static List<Float>
    getAt(float[] array, IntRange range)
    Supports the subscript operator for a float array with an IntRange giving the desired indices.
    static List<Float>
    getAt(float[] array, ObjectRange range)
    Supports the subscript operator for a float array with an ObjectRange giving the desired indices.
    static List<Float>
    getAt(float[] array, Range<?> range)
    Supports the subscript operator for a float array with a range giving the desired indices.
    static List<Float>
    getAt(float[] array, Collection<?> indices)
    Supports the subscript operator for a float array with a (potentially nested) collection giving the desired indices.
    static List<Integer>
    getAt(int[] array, IntRange range)
    Supports the subscript operator for an int array with an IntRange giving the desired indices.
    static List<Integer>
    getAt(int[] array, ObjectRange range)
    Supports the subscript operator for an int array with an ObjectRange giving the desired indices.
    static List<Integer>
    getAt(int[] array, Range<?> range)
    Supports the subscript operator for an int array with a range giving the desired indices.
    static List<Integer>
    getAt(int[] array, Collection<?> indices)
    Supports the subscript operator for an int array with a (potentially nested) collection giving the desired indices.
    static List<Long>
    getAt(long[] array, IntRange range)
    Supports the subscript operator for a long array with an IntRange giving the desired indices.
    static List<Long>
    getAt(long[] array, ObjectRange range)
    Supports the subscript operator for a long array with an ObjectRange giving the desired indices.
    static List<Long>
    getAt(long[] array, Range<?> range)
    Supports the subscript operator for a long array with a range giving the desired indices.
    static List<Long>
    getAt(long[] array, Collection<?> indices)
    Supports the subscript operator for a long array with a (potentially nested) collection giving the desired indices.
    static List<Short>
    getAt(short[] array, IntRange range)
    Supports the subscript operator for a short array with an IntRange giving the desired indices.
    static List<Short>
    getAt(short[] array, ObjectRange range)
    Supports the subscript operator for a short array with an ObjectRange giving the desired indices.
    static List<Short>
    getAt(short[] array, Range<?> range)
    Supports the subscript operator for a short array with a range giving the desired indices.
    static List<Short>
    getAt(short[] array, Collection<?> indices)
    Supports the subscript operator for a short array with a (potentially nested) collection giving the desired indices.
    static <T> List<T>
    getAt(T[] array, EmptyRange<?> range)
    Supports the subscript operator for an object array with an EmptyRange.
    static <T> List<T>
    getAt(T[] array, IntRange range)
    Supports the subscript operator for an object array with an IntRange giving the desired indices.
    static <T> List<T>
    getAt(T[] array, ObjectRange range)
    Supports the subscript operator for an object array with an ObjectRange giving the desired indices.
    static <T> List<T>
    getAt(T[] array, Range<?> range)
    Supports the subscript operator for an object array with a range giving the desired indices.
    static <T> List<T>
    getAt(T[] array, Collection<?> indices)
    Selects a List of items from an array using a Collection to identify the indices to be selected.
    static IntRange
    getIndices(boolean[] self)
    Returns indices of the boolean array.
    static IntRange
    getIndices(byte[] self)
    Returns indices of the byte array.
    static IntRange
    getIndices(char[] self)
    Returns indices of the char array.
    static IntRange
    getIndices(double[] self)
    Returns indices of the double array.
    static IntRange
    getIndices(float[] self)
    Returns indices of the float array.
    static IntRange
    getIndices(int[] self)
    Returns indices of the int array.
    static IntRange
    getIndices(long[] self)
    Returns indices of the long array.
    static IntRange
    getIndices(short[] self)
    Returns indices of the short array.
    static <T> IntRange
    getIndices(T[] self)
    Returns indices of the array.
    static <T> List<T>
    grep(T[] self)
    Iterates over the array returning each element that matches using the IDENTITY Closure as a filter - effectively returning all elements which satisfy Groovy truth.
    static <T> List<T>
    grep(T[] self, Object filter)
    Iterates over the array of items and returns a collection of items that match the given filter - calling the DefaultGroovyMethods.isCase(Object,Object) method used by switch statements.
    static Map
    groupBy(Object[] self, Object... closures)
    Sorts all array members into (sub)groups determined by the supplied mapping closures as per the Iterable variant of this method.
    static Map
    groupBy(Object[] self, List<Closure<?>> closures)
    Sorts all array members into (sub)groups determined by the supplied mapping closures as per the list variant of this method.
    static <K, T> Map<K,List<T>>
    groupBy(T[] self, Closure<K> closure)
    Sorts all array members into groups determined by the supplied mapping closure.
    static boolean
    head(boolean[] self)
    Returns the first item from the boolean array.
    static byte
    head(byte[] self)
    Returns the first item from the byte array.
    static char
    head(char[] self)
    Returns the first item from the char array.
    static double
    head(double[] self)
    Returns the first item from the double array.
    static float
    head(float[] self)
    Returns the first item from the float array.
    static int
    head(int[] self)
    Returns the first item from the int array.
    static long
    head(long[] self)
    Returns the first item from the long array.
    static short
    head(short[] self)
    Returns the first item from the short array.
    static <T> T
    head(T[] self)
    Returns the first item from the Object array.
    indexed(double[] self)
    Zips a double[] with indices in (index, value) order starting from index 0.
    indexed(double[] self, int offset)
    Zips a double[] with indices in (index, value) order.
    indexed(int[] self)
    Zips an int[] with indices in (index, value) order starting from index 0.
    indexed(int[] self, int offset)
    Zips an int[] with indices in (index, value) order.
    static Map<Integer,Long>
    indexed(long[] self)
    Zips a long[] with indices in (index, value) order starting from index 0.
    static Map<Integer,Long>
    indexed(long[] self, int offset)
    Zips a long[] with indices in (index, value) order.
    static boolean[]
    init(boolean[] self)
    Returns the items from the boolean array excluding the last item.
    static byte[]
    init(byte[] self)
    Returns the items from the byte array excluding the last item.
    static char[]
    init(char[] self)
    Returns the items from the char array excluding the last item.
    static double[]
    init(double[] self)
    Returns the items from the double array excluding the last item.
    static float[]
    init(float[] self)
    Returns the items from the float array excluding the last item.
    static int[]
    init(int[] self)
    Returns the items from the int array excluding the last item.
    static long[]
    init(long[] self)
    Returns the items from the long array excluding the last item.
    static short[]
    init(short[] self)
    Returns the items from the short array excluding the last item.
    static <T> T[]
    init(T[] self)
    Returns the items from the Object array excluding the last item.
    static <E, T, V extends T>
    T
    inject(E[] self, Closure<V> closure)
    Iterates through the given array as with inject(Object[],initialValue,closure), but using the first element of the array as the initialValue, and then iterating the remaining elements of the array.
    static <E, T, U extends T, V extends T>
    T
    inject(E[] self, U initialValue, Closure<V> closure)
    Iterates through the given array, passing in the initial value to the closure along with the first item.
    static <T> Iterator<T>
    iterator(T[] self)
    Returns an Iterator which traverses the given array in index order.
    static String
    join(boolean[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(boolean[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static String
    join(byte[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(byte[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static String
    join(char[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(char[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static String
    join(double[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(double[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static String
    join(float[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(float[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static String
    join(int[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(int[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static String
    join(long[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(long[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static String
    join(short[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(short[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static String
    join(Object[] self)
    Concatenates the string representation of each item in this array.
    static String
    join(Object[] self, String separator)
    Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    static boolean
    last(boolean[] self)
    Returns the last item from the boolean array.
    static byte
    last(byte[] self)
    Returns the last item from the byte array.
    static char
    last(char[] self)
    Returns the last item from the char array.
    static double
    last(double[] self)
    Returns the last item from the double array.
    static float
    last(float[] self)
    Returns the last item from the float array.
    static int
    last(int[] self)
    Returns the last item from the int array.
    static long
    last(long[] self)
    Returns the last item from the long array.
    static short
    last(short[] self)
    Returns the last item from the short array.
    static <T> T
    last(T[] self)
    Returns the last item from the array.
    static double
    max(double[] self)
    Adds max() method to double arrays.
    static double
    max(double[] self, DoubleComparator comparator)
    Selects the maximum value found from the double array using the supplier DoubleComparator to determine the maximum of any two values.
    static double
    max(double[] self, DoubleUnaryOperator operator)
    Selects the maximum value found from the double array using the supplier DoubleUnaryOperator to determine the maximum of any two values.
    static int
    max(int[] self)
    Adds max() method to int arrays.
    static int
    max(int[] self, 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.
    static int
    max(int[] self, IntUnaryOperator operator)
    Selects the maximum value found from the int array using the supplier IntUnaryOperator to determine the maximum of any two values.
    static long
    max(long[] self)
    Adds max() method to long arrays.
    static long
    max(long[] self, 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.
    static long
    max(long[] self, LongUnaryOperator operator)
    Selects the maximum value found from the long array using the supplier LongUnaryOperator to determine the maximum of any two values.
    static <T> T
    max(T[] self)
    Adds max() method to Object arrays.
    static <T> T
    max(T[] self, Closure<?> closure)
    Selects the maximum value found from the Object array using the closure to determine the correct ordering.
    static <T> T
    max(T[] self, Comparator<? super T> comparator)
    Selects the maximum value found from the Object array using the given comparator.
    static double
    maxBy(double[] self, Closure<?> closure)
    Selects the maximum value found from the double array using the closure to determine the maximum of any two values.
    static int
    maxBy(int[] self, Closure<?> closure)
    Selects the maximum value found from the int array using the closure to determine the maximum of any two values.
    static long
    maxBy(long[] self, Closure<?> closure)
    Selects the maximum value found from the long array using the closure to determine the maximum of any two values.
    static double
    maxComparing(double[] self, Comparator<Double> comparator)
    Selects the maximum value found from the double array using the comparator to determine the maximum of any two values.
    static int
    maxComparing(int[] self, Comparator<Integer> comparator)
    Selects the maximum value found from the int array using the comparator to determine the maximum of any two values.
    static long
    maxComparing(long[] self, Comparator<Long> comparator)
    Selects the maximum value found from the long array using the comparator to determine the maximum of any two values.
    static double
    min(double[] self)
    Adds min() method to double arrays.
    static double
    min(double[] self, DoubleComparator comparator)
    Selects the minimum value found from the double array using the supplier DoubleBinaryOperator as a comparator to determine the minimum of any two values.
    static double
    min(double[] self, DoubleUnaryOperator operator)
    Selects the minimum value found from the double array using the supplier DoubleUnaryOperator to determine the minimum of any two values.
    static int
    min(int[] self)
    Adds min() method to int arrays.
    static int
    min(int[] self, IntComparator comparator)
    Selects the minimum value found from the int array using the supplier IntComparator to determine the minimum of any two values.
    static int
    min(int[] self, IntUnaryOperator operator)
    Selects the minimum value found from the int array using the supplier IntUnaryOperator to determine the minimum of any two values.
    static long
    min(long[] self)
    Adds min() method to long arrays.
    static long
    min(long[] self, 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.
    static long
    min(long[] self, LongUnaryOperator operator)
    Selects the minimum value found from the long array using the supplier LongUnaryOperator to determine the minimum of any two values.
    static <T> T
    min(T[] self)
    Adds min() method to Object arrays.
    static <T> T
    min(T[] self, Closure<?> closure)
    Selects the minimum value found from the Object array using the closure to determine the correct ordering.
    static <T> T
    min(T[] self, Comparator<? super T> comparator)
    Selects the minimum value found from the Object array using the given comparator.
    static double
    minBy(double[] self, Closure<?> closure)
    Selects the minimum value found from the double array using the closure to determine the minimum of any two values.
    static int
    minBy(int[] self, Closure<?> closure)
    Selects the minimum value found from the int array using the closure to determine the minimum of any two values.
    static long
    minBy(long[] self, Closure<?> closure)
    Selects the minimum value found from the long array using the closure to determine the minimum of any two values.
    static double
    minComparing(double[] self, Comparator<Double> comparator)
    Selects the minimum value found from the double array using the comparator to determine the minimum of any two values.
    static int
    minComparing(int[] self, Comparator<Integer> comparator)
    Selects the minimum value found from the int array using the comparator to determine the minimum of any two values.
    static long
    minComparing(long[] self, Comparator<Long> comparator)
    Selects the minimum value found from the long array using the comparator to determine the minimum of any two values.
    static <T> T[]
    minus(T[] self, Iterable<?> removeMe)
    Creates a new array composed of the elements of the first array minus the elements of the given Iterable.
    static <T> T[]
    minus(T[] self, Object removeMe)
    Creates a new array composed of the elements of the given array minus every occurrence the given object.
    static <T> T[]
    minus(T[] self, Object[] removeMe)
    Creates a new array composed of the elements of the first array minus the elements of the given array.
    static <T> T[]
    plus(T[] left, Iterable<?> right)
    Creates an array containing elements from an original array plus those from an Iterable.
    static <T> T[]
    plus(T[] left, Object right)
    Creates an array containing elements from an original array plus an additional appended element.
    static <T> T[]
    plus(T[] left, Object[] right)
    Creates an array as a union of two arrays.
    static <T> T[]
    plus(T[] left, Collection<?> right)
    Creates an array containing elements from an original array plus those from a Collection.
    static boolean[]
    reverse(boolean[] self)
    Creates a new boolean array containing items which are the same as this array but in reverse order.
    static boolean[]
    reverse(boolean[] self, boolean mutate)
    Reverses the items in an array.
    static byte[]
    reverse(byte[] self)
    Creates a new byte array containing items which are the same as this array but in reverse order.
    static byte[]
    reverse(byte[] self, boolean mutate)
    Reverses the items in an array.
    static char[]
    reverse(char[] self)
    Creates a new char array containing items which are the same as this array but in reverse order.
    static char[]
    reverse(char[] self, boolean mutate)
    Reverses the items in an array.
    static double[]
    reverse(double[] self)
    Creates a new double array containing items which are the same as this array but in reverse order.
    static double[]
    reverse(double[] self, boolean mutate)
    Reverses the items in an array.
    static float[]
    reverse(float[] self)
    Creates a new float array containing items which are the same as this array but in reverse order.
    static float[]
    reverse(float[] self, boolean mutate)
    Reverses the items in an array.
    static int[]
    reverse(int[] self)
    Creates a new int array containing items which are the same as this array but in reverse order.
    static int[]
    reverse(int[] self, boolean mutate)
    Reverses the items in an array.
    static long[]
    reverse(long[] self)
    Creates a new long array containing items which are the same as this array but in reverse order.
    static long[]
    reverse(long[] self, boolean mutate)
    Reverses the items in an array.
    static short[]
    reverse(short[] self)
    Creates a new short array containing items which are the same as this array but in reverse order.
    static short[]
    reverse(short[] self, boolean mutate)
    Reverses the items in an array.
    static <T> T[]
    reverse(T[] self)
    Creates a new array containing items which are the same as this array but in reverse order.
    static <T> T[]
    reverse(T[] self, boolean mutate)
    Reverses the items in an array.
    static boolean[]
    reverseEach(boolean[] self, Closure<?> closure)
    Iterates through a boolean[] in reverse order passing each boolean to the given closure.
    static byte[]
    reverseEach(byte[] self, Closure<?> closure)
    Iterates through a byte[] in reverse order passing each byte to the given closure.
    static char[]
    reverseEach(char[] self, Closure<?> closure)
    Iterates through a char[] in reverse order passing each char to the given closure.
    static double[]
    reverseEach(double[] self, Closure<?> closure)
    Iterates through a double[] in reverse order passing each double to the given closure.
    static float[]
    reverseEach(float[] self, Closure<?> closure)
    Iterates through a float[] in reverse order passing each float to the given closure.
    static int[]
    reverseEach(int[] self, Closure<?> closure)
    Iterates through an int[] in reverse order passing each int to the given closure.
    static long[]
    reverseEach(long[] self, Closure<?> closure)
    Iterates through a long[] in reverse order passing each long to the given closure.
    static short[]
    reverseEach(short[] self, Closure<?> closure)
    Iterates through a short[] in reverse order passing each short to the given closure.
    static <T> T[]
    reverseEach(T[] self, Closure<?> closure)
    Iterates over each element of the array in the reverse order.
    static <T> void
    shuffle(T[] self)
    Randomly reorders the elements of the specified array.
    static <T> void
    shuffle(T[] self, Random rnd)
    Randomly reorders the elements of the specified array using the specified random instance as the source of randomness.
    static <T> T[]
    shuffled(T[] self)
    Creates a new array containing the elements of the specified array but in a random order.
    static <T> T[]
    shuffled(T[] self, Random rnd)
    Creates a new array containing the elements of the specified array but in a random order using the specified random instance as the source of randomness.
    static int
    size(boolean[] self)
    Provides arrays with a size method similar to collections.
    static int
    size(byte[] self)
    Provides arrays with a size method similar to collections.
    static int
    size(char[] self)
    Provides arrays with a size method similar to collections.
    static int
    size(double[] self)
    Provides arrays with a size method similar to collections.
    static int
    size(float[] self)
    Provides arrays with a size method similar to collections.
    static int
    size(int[] self)
    Provides arrays with a size method similar to collections.
    static int
    size(long[] self)
    Provides arrays with a size method similar to collections.
    static int
    size(short[] self)
    Provides arrays with a size method similar to collections.
    static int
    size(Object[] self)
    Provides the standard Groovy size() method for an array.
    static <T> T[]
    sort(T[] self)
    Modifies this array so that its elements are in sorted order.
    static <T> T[]
    sort(T[] self, boolean mutate)
    Sorts the given array into sorted order.
    static <T> T[]
    sort(T[] self, boolean mutate, Closure<?> closure)
    Modifies this array so that its elements are in sorted order using the Closure to determine the correct ordering.
    static <T> T[]
    sort(T[] self, boolean mutate, Comparator<? super T> comparator)
    Modifies this array so that its elements are in sorted order as determined by the given comparator.
    static <T> T[]
    sort(T[] self, Closure<?> closure)
    Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.
    static <T> T[]
    sort(T[] self, Comparator<? super T> comparator)
    Sorts the given array into sorted order using the given comparator.
    static <T> Collection<Collection<T>>
    split(T[] self, Closure<?> closure)
    Splits all items into two collections based on the closure condition.
    static byte
    sum(byte[] self)
    Sums the items in an array.
    static byte
    sum(byte[] self, byte initialValue)
    Sums the items in an array, adding the result to some initial value.
    static char
    sum(char[] self)
    Sums the items in an array.
    static char
    sum(char[] self, char initialValue)
    Sums the items in an array, adding the result to some initial value.
    static double
    sum(double[] self)
    Sums the items in an array.
    static double
    sum(double[] self, double initialValue)
    Sums the items in an array, adding the result to some initial value.
    static float
    sum(float[] self)
    Sums the items in an array.
    static float
    sum(float[] self, float initialValue)
    Sums the items in an array, adding the result to some initial value.
    static int
    sum(int[] self)
    Sums the items in an array.
    static int
    sum(int[] self, int initialValue)
    Sums the items in an array, adding the result to some initial value.
    static long
    sum(long[] self)
    Sums the items in an array.
    static long
    sum(long[] self, long initialValue)
    Sums the items in an array, adding the result to some initial value.
    static short
    sum(short[] self)
    Sums the items in an array.
    static short
    sum(short[] self, short initialValue)
    Sums the items in an array, adding the result to some initial value.
    static Object
    sum(Object[] self)
    Sums the items in an array.
    static Object
    sum(Object[] self, Object initialValue)
    Sums the items in an array, adding the result to some initial value.
    static <T> Object
    sum(T[] self, Closure<?> closure)
    Sums the result of applying a closure to each item of an array.
    static <T> Object
    sum(T[] self, Object initialValue, Closure<?> closure)
    Sums the result of applying a closure to each item of an array to some initial value.
    static boolean[]
    swap(boolean[] self, int i, int j)
    Swaps two elements at the specified positions.
    static byte[]
    swap(byte[] self, int i, int j)
    Swaps two elements at the specified positions.
    static char[]
    swap(char[] self, int i, int j)
    Swaps two elements at the specified positions.
    static double[]
    swap(double[] self, int i, int j)
    Swaps two elements at the specified positions.
    static float[]
    swap(float[] self, int i, int j)
    Swaps two elements at the specified positions.
    static int[]
    swap(int[] self, int i, int j)
    Swaps two elements at the specified positions.
    static long[]
    swap(long[] self, int i, int j)
    Swaps two elements at the specified positions.
    static short[]
    swap(short[] self, int i, int j)
    Swaps two elements at the specified positions.
    static <T> T[]
    swap(T[] self, int i, int j)
    Swaps two elements at the specified positions.
    static boolean[]
    tail(boolean[] self)
    Returns the items from the boolean array excluding the first item.
    static byte[]
    tail(byte[] self)
    Returns the items from the byte array excluding the first item.
    static char[]
    tail(char[] self)
    Returns the items from the char array excluding the first item.
    static double[]
    tail(double[] self)
    Returns the items from the double array excluding the first item.
    static float[]
    tail(float[] self)
    Returns the items from the float array excluding the first item.
    static int[]
    tail(int[] self)
    Returns the items from the int array excluding the first item.
    static long[]
    tail(long[] self)
    Returns the items from the long array excluding the first item.
    static short[]
    tail(short[] self)
    Returns the items from the short array excluding the first item.
    static <T> T[]
    tail(T[] self)
    Returns the items from the array excluding the first item.
    static <T> T[]
    take(T[] self, int num)
    Returns the first num elements from the head of this array.
    static <T> T[]
    takeRight(T[] self, int num)
    Returns the last num elements from the tail of this array.
    static <T> T[]
    takeWhile(T[] self, Closure<?> condition)
    Returns the longest prefix of this array where each element passed to the given closure evaluates to true.
    static List<Boolean>
    toList(boolean[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static List<Byte>
    toList(byte[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static List<Character>
    toList(char[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static List<Double>
    toList(double[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static List<Float>
    toList(float[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static List<Integer>
    toList(int[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static List<Long>
    toList(long[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static List<Short>
    toList(short[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static <T> List<T>
    toList(T[] self)
    Converts this array to a List of the same size, with each element added to the list.
    static Set<Boolean>
    toSet(boolean[] self)
    Converts this array to a Set, with each unique element added to the set.
    static Set<Byte>
    toSet(byte[] self)
    Converts this array to a Set, with each unique element added to the set.
    static Set<Character>
    toSet(char[] self)
    Converts this array to a Set, with each unique element added to the set.
    static Set<Double>
    toSet(double[] self)
    Converts this array to a Set, with each unique element added to the set.
    static Set<Float>
    toSet(float[] self)
    Converts this array to a Set, with each unique element added to the set.
    static Set<Integer>
    toSet(int[] self)
    Converts this array to a Set, with each unique element added to the set.
    static Set<Long>
    toSet(long[] self)
    Converts this array to a Set, with each unique element added to the set.
    static Set<Short>
    toSet(short[] self)
    Converts this array to a Set, with each unique element added to the set.
    static <T> Set<T>
    toSet(T[] self)
    Converts this array to a Set, with each unique element added to the set.
    static <T> T[]
    toSorted(T[] self)
    Returns a sorted version of the given array using the supplied comparator.
    static <T> T[]
    toSorted(T[] self, Closure<?> closure)
    Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.
    static <T> T[]
    toSorted(T[] self, Comparator<? super T> comparator)
    Returns a sorted version of the given array using the supplied comparator to determine the resulting order.
    static SpreadMap
    Creates a spreadable map from this array.
    static String
    toString(boolean[] self)
    Returns the string representation of the given array.
    static String
    toString(byte[] self)
    Returns the string representation of the given array.
    static String
    toString(char[] self)
    Returns the string representation of the given array.
    static String
    toString(double[] self)
    Returns the string representation of the given array.
    static String
    toString(float[] self)
    Returns the string representation of the given array.
    static String
    toString(int[] self)
    Returns the string representation of the given array.
    static String
    toString(long[] self)
    Returns the string representation of the given array.
    static String
    toString(short[] self)
    Returns the string representation of the given array.
    static String
    toString(Object[] self)
    Returns the string representation of the given array.
    static <T> T[]
    toUnique(T[] self)
    Returns a new Array containing the items from the original Array but with duplicates removed using the natural ordering of the items in the array.
    static <T> T[]
    toUnique(T[] self, Closure<?> closure)
    Returns a new Array containing the items from the original Array but with duplicates removed with the supplied closure determining which items are unique.
    static <T> T[]
    toUnique(T[] self, Comparator<? super T> comparator)
    Returns a new Array containing the items from the original Array but with duplicates removed with the supplied comparator determining which items are unique.
    static boolean[][]
    transpose(boolean[][] self)
    A transpose method for 2D boolean arrays.
    static byte[][]
    transpose(byte[][] self)
    A transpose method for 2D byte arrays.
    static char[][]
    transpose(char[][] self)
    A transpose method for 2D char arrays.
    static double[][]
    transpose(double[][] self)
    A transpose method for 2D double arrays.
    static float[][]
    transpose(float[][] self)
    A transpose method for 2D float arrays.
    static int[][]
    transpose(int[][] self)
    A transpose method for 2D int arrays.
    static long[][]
    transpose(long[][] self)
    A transpose method for 2D long arrays.
    static short[][]
    transpose(short[][] self)
    A transpose method for 2D short arrays.
    static Object[]
    union(Object[] left, Iterable<?> right)
    Creates an Object array containing elements from an original array plus those from an Iterable.
    static Object[]
    union(Object[] left, Object right)
    Creates an Object array containing elements from an original array plus an additional appended element.
    static Object[]
    union(Object[] left, Object[] right)
    Creates an Object array as a union of two arrays.
    static Object[]
    union(Object[] left, Collection<?> right)
    Creates an object array containing elements from an original array plus those from a Collection.
    static <K, V> Map<K,V>
    withCollectedKeys(V[] values, Function<? super V,K> keyTransform)
    A variant of withCollectedKeys for arrays.
    static <K, V> Map<K,V>
    withCollectedKeys(V[] values, Map<K,V> collector, Function<? super V,K> keyTransform)
    A variant of withCollectedKeys for arrays.
    static <K, V> Map<K,V>
    withCollectedValues(K[] keys, Function<? super K,V> valueTransform)
    A variant of withCollectedValues for arrays.
    static <K, V> Map<K,V>
    withCollectedValues(K[] keys, Map<K,V> collector, Function<? super K,V> valueTransform)
    A variant of withCollectedValues for arrays.

    Methods inherited from class java.lang.Object

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

    • any

      public static boolean any(boolean[] self)
      Iterates over the contents of a boolean Array, and checks whether any element is true.
       boolean[] array1 = [false, true]
       assert array1.any()
       boolean[] array2 = [false]
       assert !array2.any()
       
      Parameters:
      self - the boolean array over which we iterate
      Returns:
      true if any boolean is true
      Since:
      5.0.0
    • any

      public static boolean any(boolean[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a boolean Array, and checks whether a predicate is valid for at least one element.
       boolean[] array = [true]
       assert array.any{ it }
       assert !array.any{ !it }
       
      Parameters:
      self - the boolean array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the booleans matches the closure predicate
      Since:
      5.0.0
    • any

      public static boolean any(byte[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a byte Array, and checks whether a predicate is valid for at least one element.
       byte[] array = [0, 1, 2]
       assert array.any{ it > 1 }
       assert !array.any{ it > 3 }
       
      Parameters:
      self - the byte array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the bytes matches the closure predicate
      Since:
      5.0.0
    • any

      public static boolean any(char[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a char Array, and checks whether a predicate is valid for at least one element.
       char[] array = ['a', 'b', 'c']
       assert array.any{ it <= 'a' }
       assert !array.any{ it < 'a' }
       
      Parameters:
      self - the char array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the chars matches the closure predicate
      Since:
      5.0.0
    • any

      public static boolean any(short[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a short Array, and checks whether a predicate is valid for at least one element.
       short[] array = [0, 1, 2]
       assert array.any{ it > 1 }
       assert !array.any{ it > 3 }
       
      Parameters:
      self - the char array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the shorts matches the closure predicate
      Since:
      5.0.0
    • any

      public static boolean any(int[] self, @ClosureParams(Component.class) Closure<?> predicate)
      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 }
       
      Parameters:
      self - the int array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the ints matches the closure predicate
      Since:
      5.0.0
    • any

      public static boolean any(long[] self, @ClosureParams(Component.class) 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:
      self - the long array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the longs matches the closure predicate
      Since:
      5.0.0
    • any

      public static boolean any(float[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a float Array, and checks whether a predicate is valid for at least one element.
       float[] array = [0.0f, 1.0f, 2.0f]
       assert array.any{ it > 1.5f }
       assert !array.any{ it > 2.5f }
       
      Parameters:
      self - the float array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the floats matches the closure predicate
      Since:
      5.0.0
    • any

      public static boolean any(double[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a double Array, and checks whether a predicate is valid for at least one element.
       double[] array = [0.0d, 1.0d, 2.0d]
       assert array.any{ it > 1.5d }
       assert !array.any{ it > 2.5d }
       
      Parameters:
      self - the double array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the doubles matches the closure predicate
      Since:
      5.0.0
    • any

      public static <T> boolean any(T[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of an Array, and checks whether a predicate is valid for at least one element.
      Parameters:
      self - the array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if any iteration for the object matches the closure predicate
      Since:
      2.5.0
    • asBoolean

      public static boolean asBoolean(boolean[] self)
      Coerces a boolean array to a boolean value. A boolean array is false if the array is of length 0, and true otherwise.
      Parameters:
      self - an array
      Returns:
      the array's boolean value
      Since:
      1.7.4
    • asBoolean

      public static boolean asBoolean(byte[] self)
      Coerces a byte array to a boolean value. A byte array is false if the array is null or of length 0, and true otherwise.
       byte[] array1 = []
       assert !array1
       byte[] array2 = [0]
       assert array2
       
      Parameters:
      self - an array
      Returns:
      the array's boolean value
      Since:
      1.7.4
    • asBoolean

      public static boolean asBoolean(char[] self)
      Coerces a char array to a boolean value. A char array is false if the array is of length 0, and true otherwise.
      Parameters:
      self - an array
      Returns:
      the array's boolean value
      Since:
      1.7.4
    • asBoolean

      public static boolean asBoolean(short[] self)
      Coerces a short array to a boolean value. A short array is false if the array is of length 0, and true otherwise.
      Parameters:
      self - an array
      Returns:
      the array's boolean value
      Since:
      1.7.4
    • asBoolean

      public static boolean asBoolean(int[] self)
      Coerces an int array to a boolean value. An int array is false if the array is of length 0, and true otherwise.
      Parameters:
      self - an array
      Returns:
      the array's boolean value
      Since:
      1.7.4
    • asBoolean

      public static boolean asBoolean(long[] self)
      Coerces a long array to a boolean value. A long array is false if the array is of length 0, and true otherwise.
      Parameters:
      self - an array
      Returns:
      the array's boolean value
      Since:
      1.7.4
    • asBoolean

      public static boolean asBoolean(float[] self)
      Coerces a float array to a boolean value. A float array is false if the array is of length 0, and true otherwise.
      Parameters:
      self - an array
      Returns:
      the array's boolean value
      Since:
      1.7.4
    • asBoolean

      public static boolean asBoolean(double[] self)
      Coerces a double array to a boolean value. A double array is false if the array is of length 0, and true otherwise.
      Parameters:
      self - an array
      Returns:
      the array's boolean value
      Since:
      1.7.4
    • asBoolean

      public static boolean asBoolean(Object[] self)
      Coerces an object array to a boolean value. An Object array is false if the array is of length 0. and to true otherwise
      Parameters:
      self - the array
      Returns:
      the boolean value
      Since:
      1.7.0
    • asType

      public static <T> T asType(Object[] self, Class<T> type)
      Converts the given array to either a List, Set, or SortedSet. If the given class is something else, the call is deferred to DefaultGroovyMethods.asType(Object,Class).
      Parameters:
      self - an array
      type - the desired class
      Returns:
      the object resulting from this type conversion
      Since:
      1.5.1
    • average

      public static BigDecimal average(byte[] self)
      Calculates the average of the bytes in the array.
      assert 5.0G == ([2,4,6,8] as byte[]).average()
      Parameters:
      self - The array of values to calculate the average of
      Returns:
      The average of the items
      Since:
      3.0.0
    • average

      public static BigDecimal average(short[] self)
      Calculates the average of the shorts in the array.
      assert 5.0G == ([2,4,6,8] as short[]).average()
      Parameters:
      self - The array of values to calculate the average of
      Returns:
      The average of the items
      Since:
      3.0.0
    • average

      public static BigDecimal average(int[] self)
      Calculates the average of the ints in the array.
      assert 5.0G == ([2,4,6,8] as int[]).average()
      Parameters:
      self - The array of values to calculate the average of
      Returns:
      The average of the items
      Since:
      3.0.0
    • average

      public static BigDecimal average(long[] self)
      Calculates the average of the longs in the array.
      assert 5.0G == ([2,4,6,8] as long[]).average()
      Parameters:
      self - The array of values to calculate the average of
      Returns:
      The average of the items
      Since:
      3.0.0
    • average

      public static double average(float[] self)
      Calculates the average of the floats in the array.
      assert 5.0d == ([2,4,6,8] as float[]).average()
      Parameters:
      self - The array of values to calculate the average of
      Returns:
      The average of the items
      Since:
      3.0.0
    • average

      public static double average(double[] self)
      Calculates the average of the doubles in the array.
      assert 5.0d == ([2,4,6,8] as double[]).average()
      Parameters:
      self - The array of values to calculate the average of
      Returns:
      The average of the items
      Since:
      3.0.0
    • average

      public static Object average(Object[] self)
      Averages the items in an array. This is equivalent to invoking the "plus" method on all items in the array and then dividing by the total count using the "div" method for the resulting sum.
       assert 3 == ([1, 2, 6] as Integer[]).average()
       
      Parameters:
      self - The array of values to average
      Returns:
      The average of all the items
      Since:
      3.0.0
      See Also:
    • average

      public static <T> Object average(T[] self, @ClosureParams(Component.class) Closure<?> closure)
      Averages the result of applying a closure to each item of an array. array.average(closure) is equivalent to: array.collect(closure).average().
       def (nums, strings) = [[1, 3] as Integer[], ['to', 'from'] as String[]]
       assert 20 == nums.average { it * 10 }
       assert 3 == strings.average { it.size() }
       assert 3 == strings.average (String::size)
       
      Parameters:
      self - An array
      closure - a single parameter closure that returns a (typically) numeric value.
      Returns:
      The average of the values returned by applying the closure to each item of the array.
      Since:
      3.0.0
    • chop

      public static List<List<Boolean>> chop(boolean[] self, int... chopSizes)
      Chops the boolean 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.
       boolean[] array = [false, true, false]
       assert array.chop(1, 2) == [[false], [true, false]]
       
      Parameters:
      self - a boolean Array to be chopped
      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:
    • chop

      public static List<List<Byte>> chop(byte[] self, int... chopSizes)
      Chops the byte 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.
       byte[] array = [0, 1, 2]
       assert array.chop(1, 2) == [[0], [1, 2]]
       
      Parameters:
      self - a byte Array to be chopped
      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:
    • chop

      public static List<List<Character>> chop(char[] self, int... chopSizes)
      Chops the char 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.
       char[] array = [0, 1, 2]
       assert array.chop(1, 2) == [[0], [1, 2]]
       
      Parameters:
      self - a char Array to be chopped
      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:
    • chop

      public static List<List<Short>> chop(short[] self, int... chopSizes)
      Chops the short 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.
       short[] array = [0, 1, 2]
       assert array.chop(1, 2) == [[0], [1, 2]]
       
      Parameters:
      self - a short Array to be chopped
      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:
    • chop

      public static List<List<Integer>> chop(int[] self, int... chopSizes)
      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]]
       
      Parameters:
      self - an int Array to be chopped
      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:
    • chop

      public static List<List<Long>> chop(long[] self, 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:
      self - a long Array to be chopped
      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:
    • chop

      public static List<List<Float>> chop(float[] self, int... chopSizes)
      Chops the float 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.
       float[] array = [0, 1, 2]
       assert array.chop(1, 2) == [[0], [1, 2]]
       
      Parameters:
      self - a float Array to be chopped
      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:
    • chop

      public static List<List<Double>> chop(double[] self, int... chopSizes)
      Chops the double 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.
       double[] array = [0, 1, 2]
       assert array.chop(1, 2) == [[0], [1, 2]]
       
      Parameters:
      self - a double Array to be chopped
      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:
    • chop

      public static <T> List<List<T>> chop(T[] self, int... chopSizes)
      Chops the 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.
      Parameters:
      self - an Array to be chopped
      chopSizes - the sizes for the returned pieces
      Returns:
      a list of lists chopping the original array elements into pieces determined by chopSizes
      Since:
      2.5.2
      See Also:
    • collate

      public static <T> List<List<T>> collate(T[] self, int size)
      Collates an array.
      Parameters:
      self - an array
      size - the length of each sub-list in the returned list
      Returns:
      a List containing the array values collated into sub-lists
      Since:
      2.5.0
      See Also:
    • collate

      public static <T> List<List<T>> collate(T[] self, int size, int step)
      Collates an array into sub-lists.
      Parameters:
      self - an array
      size - the length of each sub-list in the returned list
      step - the number of elements to step through for each sub-list
      Returns:
      a List containing the array elements collated into sub-lists
      Since:
      2.5.0
      See Also:
    • collate

      public static <T> List<List<T>> collate(T[] self, int size, boolean keepRemainder)
      Collates this array into sub-lists.
      Parameters:
      self - an array
      size - the length of each sub-list in the returned list
      keepRemainder - if true, any remaining elements are returned as sub-lists. Otherwise they are discarded
      Returns:
      a List containing the array elements collated into sub-lists
      Since:
      2.5.0
      See Also:
    • collate

      public static <T> List<List<T>> collate(T[] self, int size, int step, boolean keepRemainder)
      Collates this array into sub-lists.
      Parameters:
      self - an array
      size - the length of each sub-list in the returned list
      step - the number of elements to step through for each sub-list
      keepRemainder - if true, any remaining elements are returned as sub-lists. Otherwise they are discarded
      Returns:
      a List containing the array elements collated into sub-lists
      Since:
      2.5.0
    • collect

      public static <E, T> List<T> collect(E[] self, @ClosureParams(Component.class) Closure<T> transform)
      Iterates through this Array transforming each item into a new value using the transform closure, returning a list of transformed values.
      Parameters:
      self - an array
      transform - the closure used to transform each item of the Array
      Returns:
      A list of the transformed values.
      Since:
      2.5.0
    • collect

      public static <E, T, C extends Collection<T>> C collect(E[] self, C collector, @ClosureParams(Component.class) Closure<? extends T> transform)
      Iterates through this Array transforming each item into a new value using the transform closure and adding it to the supplied collector.
       Integer[] nums = [1,2,3]
       List answer = []
       nums.collect(answer) { it * 2 }
       assert [2,4,6] == answer
       
      Parameters:
      self - an array
      collector - the Collection to which the transformed values are added
      transform - the closure used to transform each item
      Returns:
      The collector with all transformed values added to it.
      Since:
      2.5.0
    • collectEntries

      public static <K, V, E> Map<K,V> collectEntries(E[] self)
      A variant of collectEntries using the identity closure as the transform.
      Parameters:
      self - an array
      Returns:
      the collector with all transformed values added to it
      Since:
      1.8.5
      See Also:
    • collectEntries

      public static <K, V, E> Map<K,V> collectEntries(E[] self, Map<K,V> collector)
      A variant of collectEntries using the identity closure as the transform.
      Parameters:
      self - an array
      collector - the Map into which the transformed entries are put
      Returns:
      the collector with all transformed values added to it
      Since:
      1.8.5
      See Also:
    • collectEntries

      public static <K, V, E> Map<K,V> collectEntries(E[] self, @ClosureParams(Component.class) Closure<?> transform)
      Iterates through this array transforming each item using the transform closure and returning a map of the resulting transformed entries.
       def letters = "abc"
       def nums = [0, 1, 2] as Integer[]
       // collect letters with index using list style
       assert nums.collectEntries { index -> [index, letters[index]] } == [0:'a', 1:'b', 2:'c']
       // collect letters with index using map style
       assert nums.collectEntries { index -> [(index): letters[index]] } == [0:'a', 1:'b', 2:'c']
       
      Note: When using the list-style of result, the behavior is 'def (key, value) = listResultFromClosure'. While we strongly discourage using a list of size other than 2, Groovy's normal semantics apply in this case; throwing away elements after the second one and using null for the key or value for the case of a shortened list.
      Parameters:
      self - a Collection
      transform - the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value
      Returns:
      a Map of the transformed entries
      Since:
      1.7.9
      See Also:
    • collectEntries

      public static <K, V, E> Map<K,V> collectEntries(E[] self, Map<K,V> collector, @ClosureParams(Component.class) Closure<?> transform)
      Iterates through this array transforming each item using the transform closure and returning a map of the resulting transformed entries.
       def letters = "abc"
       def nums = [0, 1, 2] as Integer[]
       // collect letters with index
       assert nums.collectEntries( [:] ) { index -> [index, letters[index]] } == [0:'a', 1:'b', 2:'c']
       assert nums.collectEntries( [4:'d'] ) { index ->
           [(index+1): letters[index]] } == [1:'a', 2:'b', 3:'c', 4:'d']
       
      Note: When using the list-style of result, the behavior is 'def (key, value) = listResultFromClosure'. While we strongly discourage using a list of size other than 2, Groovy's normal semantics apply in this case; throwing away elements after the second one and using null for the key or value for the case of a shortened list. If your collector Map doesn't support null keys or values, you might get a runtime error, e.g. NullPointerException or IllegalArgumentException.
      Parameters:
      self - an array
      collector - the Map into which the transformed entries are put
      transform - the closure used for transforming, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value
      Returns:
      the collector with all transformed values added to it
      Since:
      1.7.9
      See Also:
    • collectEntries

      public static <K, V, E> Map<K,V> collectEntries(E[] self, Function<? super E,K> keyTransform, Function<? super E,V> valueTransform)
      A variant of collectEntries for arrays with separate functions for transforming the keys and values.
       String[] languages = ['Groovy', 'Java', 'Kotlin', 'Scala']
       def firstLetter = s -> s[0]
       assert languages.collectEntries(firstLetter, String::size) == [G:6, J:4, K:6, S:5]
       
      Parameters:
      self - an array
      keyTransform - a function for transforming array elements into keys
      valueTransform - a function for transforming array elements into values
      Returns:
      a Map of the transformed entries
      Since:
      5.0.0
    • collectEntries

      public static <K, V, E> Map<K,V> collectEntries(E[] self, Map<K,V> collector, Function<? super E,K> keyTransform, Function<? super E,V> valueTransform)
      A variant of collectEntries for arrays with separate functions for transforming the keys and values. The supplied collector map is used as the destination for transformed entries.
      Parameters:
      self - an array
      collector - the Map into which the transformed entries are put
      keyTransform - a function for transforming array elements into keys
      valueTransform - a function for transforming array elements into values
      Returns:
      the collector with all transformed values added to it
      Since:
      5.0.0
    • collectMany

      public static <T, E> List<T> collectMany(E[] self, @ClosureParams(Component.class) Closure<? extends Collection<? extends T>> projection)
      Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.
       def nums = [1, 2, 3, 4, 5, 6] as Object[]
       def squaresAndCubesOfEvens = nums.collectMany{ it % 2 ? [] : [it**2, it**3] }
       assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216]
       
      Parameters:
      self - an array
      projection - a projecting Closure returning a collection of items
      Returns:
      A list created from the projected collections concatenated (flattened) together.
      Since:
      1.8.1
    • collectMany

      public static <T, E, C extends Collection<T>> C collectMany(E[] self, C collector, @ClosureParams(Component.class) Closure<? extends Collection<? extends T>> projection)
      Projects each item from a source array to a collection and concatenates (flattens) the resulting collections into a single list.
       def nums = [1, 2, 3, 4, 5, 6] as Object[]
       def squaresAndCubesOfEvens = nums.collectMany{ it % 2 ? [] : [it**2, it**3] }
       assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216]
       
      Parameters:
      self - an array
      collector - an initial collection to add the projected items to
      projection - a projecting Closure returning a collection of items
      Returns:
      The collector with the projected collections concatenated (flattened) to it.
      Since:
      1.8.1
    • contains

      public static boolean contains(boolean[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • contains

      public static boolean contains(byte[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • contains

      public static boolean contains(char[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • contains

      public static boolean contains(short[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • contains

      public static boolean contains(int[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • contains

      public static boolean contains(long[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • contains

      public static boolean contains(float[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • contains

      public static boolean contains(double[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • contains

      public static boolean contains(Object[] self, Object value)
      Checks whether the array contains the given value.
      Parameters:
      self - the array we are searching
      value - the value being searched for
      Returns:
      true if the array contains the value
      Since:
      1.8.6
    • count

      public static Number count(boolean[] self, 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).
       boolean[] array = [false, true, true]
       assert array.count(true) == 2
       
      Parameters:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
      See Also:
    • count

      public static Number count(byte[] self, 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).
       byte[] array = [10, 20, 20, 30]
       assert array.count(20) == 2
       
      Parameters:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
      See Also:
    • count

      public static Number count(char[] self, 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).
       char[] array = ['x', 'y', 'z', 'z', 'y']
       assert array.count('y') == 2
       
      Parameters:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
      See Also:
    • count

      public static Number count(short[] self, 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).
       short[] array = [10, 20, 20, 30]
       assert array.count(20) == 2
       
      Parameters:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
      See Also:
    • count

      public static Number count(int[] self, 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).
       int[] array = [10, 20, 20, 30]
       assert array.count(20) == 2
       
      Parameters:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
      See Also:
    • count

      public static Number count(long[] self, 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:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
      See Also:
    • count

      public static Number count(float[] self, 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).
       float[] array = [10.0f, 20.0f, 20.0f, 30.0f]
       assert array.count(20.0f) == 2
       
      Parameters:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
      See Also:
    • count

      public static Number count(double[] self, 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).
       double[] array = [10.0d, 20.0d, 20.0d, 30.0d]
       assert array.count(20.0d) == 2
       
      Parameters:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
      See Also:
    • count

      public static Number count(Object[] self, 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 or equals(value) ).
      Parameters:
      self - the array within which we count the number of occurrences
      value - the value being searched for
      Returns:
      the number of occurrences
      Since:
      1.6.4
    • count

      public static <T> Number count(T[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Counts the number of occurrences which satisfy the given closure from inside this array.
      Parameters:
      self - the array within which we count the number of occurrences
      predicate - a closure condition
      Returns:
      the number of occurrences
      Since:
      1.8.0
    • countBy

      public static <K, E> Map<K,Integer> countBy(E[] self, @ClosureParams(Component.class) Closure<K> closure)
      Sorts all array members into groups determined by the supplied mapping closure and counts the group size. The closure should return the key that each item should be grouped by. The returned Map will have an entry for each distinct key returned from the closure, with each value being the frequency of items occurring for that group.

      Example usage:

      assert ([1,2,2,2,3] as Object[]).countBy{ it % 2 } == [1:2, 0:3]
      Parameters:
      self - an array to group and count
      closure - a closure mapping items to the frequency keys
      Returns:
      a new Map grouped by keys with frequency counts
      Since:
      1.8.0
      See Also:
    • drop

      public static <T> T[] drop(T[] self, int num)
      Drops the given number of elements from the head of this array if they are available.
       String[] strings = [ 'a', 'b', 'c' ]
       assert strings.drop( 0 ) == [ 'a', 'b', 'c' ] as String[]
       assert strings.drop( 2 ) == [ 'c' ] as String[]
       assert strings.drop( 5 ) == [] as String[]
       
      Parameters:
      self - the original array
      num - the number of elements to drop from this array
      Returns:
      An array consisting of all elements of this array except the first num ones, or else the empty array, if this array has less than num elements.
      Since:
      1.8.1
    • dropRight

      public static <T> T[] dropRight(T[] self, int num)
      Drops the given number of elements from the tail of this array if they are available.
       String[] strings = [ 'a', 'b', 'c' ]
       assert strings.dropRight( 0 ) == [ 'a', 'b', 'c' ] as String[]
       assert strings.dropRight( 2 ) == [ 'a' ] as String[]
       assert strings.dropRight( 5 ) == [] as String[]
       
      Parameters:
      self - the original array
      num - the number of elements to drop from this array
      Returns:
      An array consisting of all elements of this array except the last num ones, or else the empty array, if this array has less than num elements.
      Since:
      2.4.0
    • dropWhile

      public static <T> T[] dropWhile(T[] self, @ClosureParams(Component.class) Closure<?> condition)
      Create a suffix of the given array by dropping as many elements as possible from the front of the original array such that calling the given closure condition evaluates to true when passed each of the dropped elements.
       def nums = [ 1, 3, 2 ] as Integer[]
       assert nums.dropWhile{ it <= 3 } == [ ] as Integer[]
       assert nums.dropWhile{ it < 3 } == [ 3, 2 ] as Integer[]
       assert nums.dropWhile{ it != 2 } == [ 2 ] as Integer[]
       assert nums.dropWhile{ it == 0 } == [ 1, 3, 2 ] as Integer[]
       
      Parameters:
      self - the original array
      condition - the closure that must evaluate to true to continue dropping elements
      Returns:
      The shortest suffix of the given array such that the given closure condition evaluates to true for each element dropped from the front of the array.
      Since:
      1.8.7
    • each

      @Incubating public static boolean[] each(boolean[] self, Consumer<Boolean> consumer)
      Iterates through a boolean[] passing each boolean to the given consumer.
       boolean[] array = [false, true, false]
       String result = ''
       array.each{ result += it.toString()[0] }
       assert result == 'ftf'
       
      Parameters:
      self - the boolean array over which we iterate
      consumer - the consumer for each boolean
      Returns:
      the self array
      Since:
      5.0.0
    • each

      @Incubating public static byte[] each(byte[] self, Consumer<Byte> consumer)
      Iterates through a byte[] passing each byte to the given consumer.
       byte[] array = [0, 1, 2]
       String result = ''
       array.each{ result += it }
       assert result == '012'
       
      Parameters:
      self - the byte array over which we iterate
      consumer - the consumer for each byte
      Returns:
      the self array
      Since:
      5.0.0
    • each

      @Incubating public static char[] each(char[] self, Consumer<Character> consumer)
      Iterates through a char[] passing each char to the given consumer.
       char[] array = ['a' as char, 'b' as char, 'c' as char]
       String result = ''
       array.each{ result += it }
       assert result == 'abc'
       
      Parameters:
      self - the char array over which we iterate
      consumer - the consumer for each char
      Returns:
      the self array
      Since:
      5.0.0
    • each

      @Incubating public static short[] each(short[] self, Consumer<Short> consumer)
      Iterates through a short[] passing each short to the given consumer.
       short[] array = [0, 1, 2]
       String result = ''
       array.each{ result += it }
       assert result == '012'
       
      Parameters:
      self - the short array over which we iterate
      consumer - the consumer for each short
      Returns:
      the self array
      Since:
      5.0.0
    • each

      @Incubating public static int[] each(int[] self, IntConsumer consumer)
      Iterates through an int[] passing each int to the given consumer.
       int[] array = [0, 1, 2]
       String result = ''
       array.each{ result += it }
       assert result == '012'
       
      Parameters:
      self - the int array over which we iterate
      consumer - the consumer for each int
      Returns:
      the self array
      Since:
      5.0.0
    • each

      @Incubating public static long[] each(long[] self, 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:
      self - the long array over which we iterate
      consumer - the consumer for each long
      Returns:
      the self array
      Since:
      5.0.0
    • each

      @Incubating public static float[] each(float[] self, Consumer<Float> consumer)
      Iterates through a float[] passing each float to the given consumer.
       float[] array = [0f, 1f, 2f]
       String result = ''
       array.each{ result += it }
       assert result == '0.01.02.0'
       
      Parameters:
      self - the float array over which we iterate
      consumer - the consumer for each float
      Returns:
      the self array
      Since:
      5.0.0
    • each

      @Incubating public static double[] each(double[] self, DoubleConsumer consumer)
      Iterates through a double[] passing each double to the given consumer.
       double[] array = [0d, 1d, 2d]
       String result = ''
       array.each{ result += it }
       assert result == '0.01.02.0'
       
      Parameters:
      self - the double array over which we iterate
      consumer - the consumer for each double
      Returns:
      the self array
      Since:
      5.0.0
    • each

      public static <T> T[] each(T[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates through an array passing each array entry to the given closure.
       String[] letters = ['a', 'b', 'c']
       String result = ''
       letters.each{ result += it }
       assert result == 'abc'
       
      Parameters:
      self - the array over which we iterate
      closure - the closure applied on each array entry
      Returns:
      the self array
      Since:
      2.5.0
    • eachByte

      public static void eachByte(byte[] self, @ClosureParams(Component.class) Closure<?> closure)
      Traverses through each byte of this byte array.
      Parameters:
      self - a byte array
      closure - a closure
      Since:
      1.5.5
    • eachByte

      public static void eachByte(Byte[] self, @ClosureParams(Component.class) Closure<?> closure)
      Traverses through each byte of this Byte array. Alias for each.
      Parameters:
      self - a Byte array
      closure - a closure
      Since:
      1.5.5
    • eachWithIndex

      public static boolean[] eachWithIndex(boolean[] self, @ClosureParams(value=FromString.class,options="Boolean,Integer") Closure<?> closure)
      Iterates through a boolean[], passing each boolean and the element's index (a counter starting at zero) to the given closure.
       boolean[] array = [false, true, false]
       String result = ''
       array.eachWithIndex{ item, index -> result += "$index($item)" }
       assert result == '0(false)1(true)2(false)'
       
      Parameters:
      self - a boolean array
      closure - a Closure to operate on each boolean
      Returns:
      the self array
      Since:
      5.0.0
    • eachWithIndex

      public static byte[] eachWithIndex(byte[] self, @ClosureParams(value=FromString.class,options="Byte,Integer") Closure<?> closure)
      Iterates through a byte[], passing each byte and the element's index (a counter starting at zero) to the given closure.
       byte[] array = [10, 20, 30]
       String result = ''
       array.eachWithIndex{ item, index -> result += "$index($item)" }
       assert result == '0(10)1(20)2(30)'
       
      Parameters:
      self - a byte array
      closure - a Closure to operate on each byte
      Returns:
      the self array
      Since:
      5.0.0
    • eachWithIndex

      public static char[] eachWithIndex(char[] self, @ClosureParams(value=FromString.class,options="Character,Integer") Closure<?> closure)
      Iterates through a char[], passing each char and the element's index (a counter starting at zero) to the given closure.
       char[] array = ['a' as char, 'b' as char, 'c' as char]
       String result = ''
       array.eachWithIndex{ item, index -> result += "$index($item)" }
       assert result == '0(a)1(b)2(c)'
       
      Parameters:
      self - a char array
      closure - a Closure to operate on each char
      Returns:
      the self array
      Since:
      5.0.0
    • eachWithIndex

      public static short[] eachWithIndex(short[] self, @ClosureParams(value=FromString.class,options="Short,Integer") Closure<?> closure)
      Iterates through a short[], passing each short and the element's index (a counter starting at zero) to the given closure.
       short[] array = [10, 20, 30]
       String result = ''
       array.eachWithIndex{ item, index -> result += "$index($item)" }
       assert result == '0(10)1(20)2(30)'
       
      Parameters:
      self - a short array
      closure - a Closure to operate on each short
      Returns:
      the self array
      Since:
      5.0.0
    • eachWithIndex

      public static int[] eachWithIndex(int[] self, @ClosureParams(value=FromString.class,options="Integer,Integer") Closure<?> closure)
      Iterates 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)'
       
      Parameters:
      self - an int array
      closure - a Closure to operate on each int
      Returns:
      the self array
      Since:
      5.0.0
    • eachWithIndex

      public static long[] eachWithIndex(long[] self, @ClosureParams(value=FromString.class,options="Long,Integer") 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:
      self - a long array
      closure - a Closure to operate on each long
      Returns:
      the self array
      Since:
      5.0.0
    • eachWithIndex

      public static float[] eachWithIndex(float[] self, @ClosureParams(value=FromString.class,options="Float,Integer") Closure<?> closure)
      Iterates through a float[], passing each float and the element's index (a counter starting at zero) to the given closure.
       float[] array = [10f, 20f, 30f]
       String result = ''
       array.eachWithIndex{ item, index -> result += "$index($item)" }
       assert result == '0(10.0)1(20.0)2(30.0)'
       
      Parameters:
      self - a float array
      closure - a Closure to operate on each float
      Returns:
      the self array
      Since:
      5.0.0
    • eachWithIndex

      public static double[] eachWithIndex(double[] self, @ClosureParams(value=FromString.class,options="Double,Integer") Closure<?> closure)
      Iterates through a double[], passing each double and the element's index (a counter starting at zero) to the given closure.
       double[] array = [10d, 20d, 30d]
       String result = ''
       array.eachWithIndex{ item, index -> result += "$index($item)" }
       assert result == '0(10.0)1(20.0)2(30.0)'
       
      Parameters:
      self - a double array
      closure - a Closure to operate on each double
      Returns:
      the self array
      Since:
      5.0.0
    • eachWithIndex

      public static <T> T[] eachWithIndex(T[] self, @ClosureParams(value=FromString.class,options="T,Integer") Closure<?> closure)
      Iterates through an array, passing each array element and the element's index (a counter starting at zero) to the given closure.
       String[] letters = ['a', 'b', 'c']
       String result = ''
       letters.eachWithIndex{ letter, index -> result += "$index:$letter" }
       assert result == '0:a1:b2:c'
       
      Parameters:
      self - an array
      closure - a Closure to operate on each array entry
      Returns:
      the self array
      Since:
      2.5.0
    • equals

      public static boolean equals(boolean[] self, boolean[] right)
      Compares the contents of this array to the contents of the given array.

      Example usage:

       boolean[] array1 = [true, false]
       boolean[] array2 = [true, false]
       assert array1 !== array2
       assert array1.equals(array2)
       
      Parameters:
      self - a boolean array
      right - the array being compared
      Returns:
      true if the contents of both arrays are equal.
      Since:
      5.0.0
    • equals

      public static boolean equals(byte[] self, byte[] right)
      Compares the contents of this array to the contents of the given array.

      Example usage:

       byte[] array1 = [4, 8]
       byte[] array2 = [4, 8]
       assert array1 !== array2
       assert array1.equals(array2)
       
      Parameters:
      self - a byte array
      right - the array being compared
      Returns:
      true if the contents of both arrays are equal.
      Since:
      5.0.0
    • equals

      public static boolean equals(char[] self, char[] right)
      Compares the contents of this array to the contents of the given array.

      Example usage:

       char[] array1 = ['a', 'b']
       char[] array2 = ['a', 'b']
       assert array1 !== array2
       assert array1.equals(array2)
       
      Parameters:
      self - a char array
      right - the array being compared
      Returns:
      true if the contents of both arrays are equal.
      Since:
      5.0.0
    • equals

      public static boolean equals(short[] self, short[] right)
      Compares the contents of this array to the contents of the given array.

      Example usage:

       short[] array1 = [4, 8]
       short[] array2 = [4, 8]
       assert array1 !== array2
       assert array1.equals(array2)
       
      Parameters:
      self - a short array
      right - the array being compared
      Returns:
      true if the contents of both arrays are equal.
      Since:
      5.0.0
    • equals

      public static boolean equals(int[] self, int[] right)
      Compares 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)
       
      Parameters:
      self - an int array
      right - the array being compared
      Returns:
      true if the contents of both arrays are equal.
      Since:
      5.0.0
    • equals

      public static boolean equals(long[] self, 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:
      self - a long array
      right - the array being compared
      Returns:
      true if the contents of both arrays are equal.
      Since:
      5.0.0
    • equals

      public static boolean equals(float[] self, float[] right)
      Compares the contents of this array to the contents of the given array.

      Example usage:

       float[] array1 = [4.0f, 8.0f]
       float[] array2 = [4.0f, 8.0f]
       assert array1 !== array2
       assert array1.equals(array2)
       
      Parameters:
      self - a float array
      right - the array being compared
      Returns:
      true if the contents of both arrays are equal.
      Since:
      5.0.0
    • equals

      public static boolean equals(double[] self, double[] right)
      Compares the contents of this array to the contents of the given array.

      Example usage:

       double[] array1 = [4.0d, 8.0d]
       double[] array2 = [4.0d, 8.0d]
       assert array1 !== array2
       assert array1.equals(array2)
       
      Parameters:
      self - a double array
      right - the array being compared
      Returns:
      true if the contents of both arrays are equal.
      Since:
      5.0.0
    • equals

      public static boolean equals(Object[] left, List<?> right)
      Determines if the contents of this array are equal to the contents of the given list, in the same order. This returns false if either collection is null.
      Parameters:
      left - an array
      right - the List being compared
      Returns:
      true if the contents of both collections are equal.
      Since:
      1.5.0
    • every

      public static boolean every(boolean[] self)
      Iterates over the contents of a boolean Array, and checks whether every element is true.
       boolean[] array1 = [false, true]
       assert !array1.every()
       boolean[] array2 = [true, true]
       assert array2.every()
       
      Parameters:
      self - the boolean array over which we iterate
      Returns:
      true if no boolean is false
      Since:
      5.0.0
    • every

      public static boolean every(boolean[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a boolean Array, and checks whether a predicate is valid for every element.
       boolean[] array = [true]
       assert array.every{ it }
       assert !array.every{ !it }
       
      Parameters:
      self - the boolean array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      5.0.0
    • every

      public static boolean every(byte[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a byte Array, and checks whether a predicate is valid for all elements.
       byte[] array = [0, 1, 2]
       assert array.every{ it < 3 }
       assert !array.every{ it > 1 }
       
      Parameters:
      self - the byte array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      5.0.0
    • every

      public static boolean every(char[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a char Array, and checks whether a predicate is valid for all elements.
       char[] array = ['a', 'b', 'c']
       assert array.every{ it <= 'd' }
       assert !array.every{ it > 'b' }
       
      Parameters:
      self - the char array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      5.0.0
    • every

      public static boolean every(short[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a short Array, and checks whether a predicate is valid for all elements.
       short[] array = [0, 1, 2]
       assert array.every{ it < 3 }
       assert !array.every{ it > 1 }
       
      Parameters:
      self - the char array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      5.0.0
    • every

      public static boolean every(int[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates 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 }
       
      Parameters:
      self - the int array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      5.0.0
    • every

      public static boolean every(long[] self, @ClosureParams(Component.class) 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:
      self - the long array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      5.0.0
    • every

      public static boolean every(float[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a float Array, and checks whether a predicate is valid for all elements.
       float[] array = [0.0f, 1.0f, 2.0f]
       assert array.every{ it < 2.5f }
       assert !array.every{ it > 1.5f }
       
      Parameters:
      self - the float array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      5.0.0
    • every

      public static boolean every(double[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Iterates over the contents of a double Array, and checks whether a predicate is valid for all elements.
       double[] array = [0.0d, 1.0d, 2.0d]
       assert array.every{ it < 2.5d }
       assert !array.every{ it > 1.5d }
       
      Parameters:
      self - the double array over which we iterate
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      5.0.0
    • every

      public static <T> boolean every(T[] self, @ClosureParams(Component.class) Closure<?> predicate)
      Used to determine if the given predicate closure is valid (i.e. returns true for all items in this Array).
      Parameters:
      self - an array
      predicate - the closure predicate used for matching
      Returns:
      true if the predicate returns true for all elements in the array
      Since:
      2.5.0
    • find

      public static <T> T find(T[] self, @ClosureParams(Component.class) Closure<?> condition)
      Finds the first element in the array that matches the given closure condition. Example:
       def list = [1,2,3] as Integer[]
       assert 2 == list.find { it > 1 }
       assert null == list.find { it > 5 }
       
      Parameters:
      self - an array
      condition - a closure condition
      Returns:
      The first element from the array that matches the condition or null if no element matches.
      Since:
      2.0
    • findAll

      public static <T> List<T> findAll(T[] self)
      Finds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth).
       def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] as Object[]
       assert items.findAll() == [1, 2, true, 'foo', [4, 5]]
       
      Parameters:
      self - an array
      Returns:
      A list of the truthy values.
      Since:
      2.0
      See Also:
    • findAll

      public static <T> List<T> findAll(T[] self, @ClosureParams(Component.class) Closure<?> condition)
      Finds all elements of the array matching the given Closure condition.
       def items = [1,2,3,4] as Integer[]
       assert [2,4] == items.findAll { it % 2 == 0 }
       
      Parameters:
      self - an array
      condition - a closure condition
      Returns:
      A list of the matching values.
      Since:
      2.0
    • findIndexOf

      public static <T> int findIndexOf(T[] self, @ClosureParams(Component.class) Closure<?> condition)
      Iterates over the elements of an array and returns the index of the first item that satisfies the condition specified by the closure.
      Parameters:
      self - an array
      condition - the matching condition
      Returns:
      The index of the first matched object or -1 if no match was found.
      Since:
      2.5.0
    • findIndexOf

      public static <T> int findIndexOf(T[] self, int startIndex, @ClosureParams(Component.class) Closure<?> condition)
      Iterates over the elements of an array, starting from a specified index, and returns the index of the first item that satisfies the condition specified by the closure.
      Parameters:
      self - an array
      startIndex - start matching from this index
      condition - the matching condition
      Returns:
      The index of the first matched object or -1 if no match was found.
      Since:
      2.5.0
    • findIndexValues

      public static <T> List<Number> findIndexValues(T[] self, @ClosureParams(Component.class) Closure<?> condition)
      Iterates over the elements of an array and returns the index values of the items that match the condition specified in the closure.
      Parameters:
      self - an array
      condition - the matching condition
      Returns:
      a list of numbers corresponding to the index values of all matched objects
      Since:
      2.5.0
    • findIndexValues

      public static <T> List<Number> findIndexValues(T[] self, Number startIndex, @ClosureParams(Component.class) Closure<?> condition)
      Iterates over the elements of an array, starting from a specified index, and returns the index values of the items that match the condition specified in the closure.
      Parameters:
      self - an array
      startIndex - start matching from this index
      condition - the matching condition
      Returns:
      a list of numbers corresponding to the index values of all matched objects
      Since:
      2.5.0
    • findLastIndexOf

      public static <T> int findLastIndexOf(T[] self, @ClosureParams(Component.class) Closure<?> condition)
      Returns the index of the last item that matches the specified condition.
       def array = new Number[]{1, 2, 1, 2, 1}
       assert array.findLastIndexOf{it==1} ==  4
       assert array.findLastIndexOf{it==2} ==  3
       assert array.findLastIndexOf{it==3} == -1
       assert array.findLastIndexOf{it>=0} ==  4
       assert array.findLastIndexOf{it<=0} == -1
       def empty = new Object[0]
       assert empty.findLastIndexOf {true} == -1
       
      Parameters:
      self - an array
      condition - the matching condition
      Returns:
      The index of the last matched object or -1 if no match was found.
      Since:
      2.5.0
    • findLastIndexOf

      public static <T> int findLastIndexOf(T[] self, int lowerBound, @ClosureParams(Component.class) Closure<?> condition)
      Returns the index of the last item that matches the specified condition that is at or beyond the given index.
       def array = new Number[]{3, 1, 2, 1, 2, 1}
       assert array.findLastIndexOf(1,{it==0}) == -1
       assert array.findLastIndexOf(1,{it==1}) ==  5
       assert array.findLastIndexOf(1,{it==2}) ==  4
       assert array.findLastIndexOf(1,{it==3}) == -1
       assert array.findLastIndexOf(0,{it==3}) ==  0
       def empty = new Object[0]
       assert empty.findLastIndexOf( 2,{true}) == -1
       assert empty.findLastIndexOf(-2,{true}) == -1
       
      Parameters:
      self - an array
      lowerBound - the minimum index
      condition - the matching condition
      Returns:
      The index of the last matched object or -1 if no match was found.
      Since:
      2.5.0
    • findResult

      public static <T> T findResult(T[] self)
      Iterates through the Array stopping once the first non-null result is found and returning that result. If all results are null, null is returned.
      Parameters:
      self - an array
      Returns:
      The first non-null result from calling the closure, or null.
      Since:
      4.0.9
    • findResult

      public static <T, U extends T, V extends T> T findResult(U[] self, V defaultResult)
      Iterates through the Array stopping once the first non-null result is found and returning that result. If all are null, the defaultResult is returned.
      Parameters:
      self - an Array
      defaultResult - an Object that should be returned if all elements are null
      Returns:
      the first non-null result from calling the closure, or the defaultValue
      Since:
      4.0.9
    • findResult

      public static <S, T> T findResult(S[] self, @ClosureParams(Component.class) Closure<T> condition)
      Iterates through the Array calling the given closure condition for each item but stopping once the first non-null result is found and returning that result. If all results are null, null is returned.
      Parameters:
      self - an array
      condition - a closure that returns a non-null value to indicate that processing should stop and the value should be returned
      Returns:
      The first non-null result from calling the closure, or null.
      Since:
      2.5.0
    • findResult

      public static <S, T, U extends T, V extends T> T findResult(S[] self, U defaultResult, @ClosureParams(Component.class) Closure<V> condition)
      Iterates through the Array calling the given closure condition for each item but stopping once the first non-null result is found and returning that result. If all are null, the defaultResult is returned.
      Parameters:
      self - an array
      defaultResult - a value that should be returned if all closure results are null
      condition - a closure that returns a non-null value to indicate that processing should stop and the value should be returned
      Returns:
      The first non-null result from calling the closure, or the defaultValue.
      Since:
      2.5.0
    • findResults

      public static <T> Collection<T> findResults(T[] self)
      Iterates through the Array collecting any non-null results.
      Parameters:
      self - an array
      Returns:
      The list of non-null values.
      Since:
      4.0.9
    • findResults

      public static <T, U> Collection<T> findResults(U[] self, @ClosureParams(Component.class) Closure<T> filteringTransform)
      Iterates through the Array transforming items using the supplied closure and collecting any non-null results.
      Parameters:
      self - an array
      filteringTransform - a closure that should return either a non-null transformed value or null for items which should be discarded
      Returns:
      The list of non-null transformed values.
      Since:
      2.5.0
    • first

      public static boolean first(boolean[] self)
      Returns the first item from the boolean array.
       boolean[] array = [true, false]
       assert array.first() == true
       
      An alias for head().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • first

      public static byte first(byte[] self)
      Returns the first item from the byte array.
       byte[] bytes = [1, 2, 3]
       assert bytes.first() == 1
       
      An alias for head().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • first

      public static char first(char[] self)
      Returns the first item from the char array.
       char[] chars = ['a', 'b', 'c']
       assert chars.first() == 'a'
       
      An alias for head().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • first

      public static short first(short[] self)
      Returns the first item from the short array.
       short[] shorts = [10, 20, 30]
       assert shorts.first() == 10
       
      An alias for head().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • first

      public static int first(int[] self)
      Returns the first item from the int array.
       int[] ints = [1, 3, 5]
       assert ints.first() == 1
       
      An alias for head().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • first

      public static long first(long[] self)
      Returns the first item from the long array.
       long[] longs = [2L, 4L, 6L]
       assert longs.first() == 2L
       
      An alias for head().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • first

      public static float first(float[] self)
      Returns the first item from the float array.
       float[] floats = [2.0f, 4.0f, 6.0f]
       assert floats.first() == 2.0f
       
      An alias for head().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • first

      public static double first(double[] self)
      Returns the first item from the double array.
       double[] doubles = [10.0d, 20.0d, 30.0d]
       assert doubles.first() == 10.0d
       
      An alias for head().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • first

      public static <T> T first(T[] self)
      Returns the first item from the array.
       def array = [3, 4, 2].toArray()
       assert array.first() == 3
       
      Parameters:
      self - an array
      Returns:
      the first item from the array
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      1.7.3
    • flatten

      public static List<Boolean> flatten(boolean[] self)
      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.
       boolean[] array = [false, true]
       assert array.flatten() == [false, true]
       
      Parameters:
      self - a boolean Array
      Returns:
      a Collection of the array elements
      Since:
      1.6.0
    • flatten

      public static List<Byte> flatten(byte[] self)
      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.
       byte[] array = [0, 1]
       assert array.flatten() == [0, 1]
       
      Parameters:
      self - a byte Array
      Returns:
      a Collection of the array elements
      Since:
      1.6.0
    • flatten

      public static List<Character> flatten(char[] self)
      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.
       char[] array = 'ab'.chars
       assert array.flatten() == ['a', 'b']
       
      Parameters:
      self - a char Array
      Returns:
      a Collection of the array elements
      Since:
      1.6.0
    • flatten

      public static List<Short> flatten(short[] self)
      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.
       short[] array = [0, 1]
       assert array.flatten() == [0, 1]
       
      Parameters:
      self - a short Array
      Returns:
      a Collection of the array elements
      Since:
      1.6.0
    • flatten

      public static List<Integer> flatten(int[] self)
      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.
       int[] array = [0, 1]
       assert array.flatten() == [0, 1]
       
      Parameters:
      self - an int Array
      Returns:
      a Collection of the array elements
      Since:
      1.6.0
    • flatten

      public static List<Long> flatten(long[] self)
      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]
       
      Parameters:
      self - a long Array to flatten
      Returns:
      a Collection of the array elements
      Since:
      1.6.0
    • flatten

      public static List<Float> flatten(float[] self)
      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.
       float[] array = [0.0f, 1.0f]
       assert array.flatten() == [0.0f, 1.0f]
       
      Parameters:
      self - a float Array to flatten
      Returns:
      a Collection of the array elements
      Since:
      1.6.0
    • flatten

      public static List<Double> flatten(double[] self)
      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.
       double[] array = [0.0d, 1.0d]
       assert array.flatten() == [0.0d, 1.0d]
       
      Parameters:
      self - a double Array to flatten
      Returns:
      a Collection of the array elements
      Since:
      1.6.0
    • flatten

      public static List<Object> flatten(Object[] self)
      Flattens an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
      Parameters:
      self - an Array to flatten
      Returns:
      S flattened Collection
      Since:
      1.6.0
    • flatten

      public static List<Boolean> flatten(boolean[][] self)
      Flattens a 2D array into a new collection. The items are copied row by row.

      Example usage:

       boolean[][] array = [[true, false], [true, false]]
       assert array.flatten() == [true, false, true, false]
       
      Parameters:
      self - a 2D boolean Array
      Returns:
      a Collection of the array elements
      Since:
      5.0.0
    • flatten

      public static List<Byte> flatten(byte[][] self)
      Flattens a 2D array into a new collection. The items are copied row by row.

      Example usage:

       byte[][] array = [[0, 1], [2, 3]]
       assert array.flatten() == [0, 1, 2, 3]
       
      Parameters:
      self - a 2D byte Array
      Returns:
      a Collection of the array elements
      Since:
      5.0.0
    • flatten

      public static List<Character> flatten(char[][] self)
      Flattens a 2D array into a new collection. The items are copied row by row.

      Example usage:

       char[][] array = ['ab'.chars, 'cd'.chars]
       assert array.flatten() == ['a', 'b', 'c', 'd']
       
      Parameters:
      self - a 2D char Array
      Returns:
      a Collection of the array elements
      Since:
      5.0.0
    • flatten

      public static List<Short> flatten(short[][] self)
      Flattens a 2D array into a new collection. The items are copied row by row.

      Example usage:

       short[][] array = [[0, 1], [2, 3]]
       assert array.flatten() == [0, 1, 2, 3]
       
      Parameters:
      self - a 2D short Array
      Returns:
      a Collection of the array elements
      Since:
      5.0.0
    • flatten

      public static List<Integer> flatten(int[][] self)
      Flattens a 2D array into a new collection. The items are copied row by row.

      Example usage:

       int[][] array = [[0, 1], [2, 3]]
       assert array.flatten() == [0, 1, 2, 3]
       
      Parameters:
      self - a 2D int Array
      Returns:
      a Collection of the array elements
      Since:
      5.0.0
    • flatten

      public static List<Long> flatten(long[][] self)
      Flattens a 2D array into a new collection. The items are copied row by row.

      Example usage:

       long[][] array = [[0, 1], [2, 3]]
       assert array.flatten() == [0, 1, 2, 3]
       
      Parameters:
      self - a 2D long Array
      Returns:
      a Collection of the array elements
      Since:
      5.0.0
    • flatten

      public static List<Float> flatten(float[][] self)
      Flattens a 2D array into a new collection. The items are copied row by row.

      Example usage:

       float[][] array = [[0.0f, 1.0f], [2.0f, 3.0f]]
       assert array.flatten() == [0.0f, 1.0f, 2.0f, 3.0f]
       
      Parameters:
      self - a 2D float Array
      Returns:
      a Collection of the array elements
      Since:
      5.0.0
    • flatten

      public static List<Double> flatten(double[][] self)
      Flattens a 2D array into a new collection. The items are copied row by row.

      Example usage:

       double[][] array = [[0.0f, 1.0f], [2.0f, 3.0f]]
       assert array.flatten() == [0.0f, 1.0f, 2.0f, 3.0f]
       
      Parameters:
      self - a 2D double Array
      Returns:
      a Collection of the array elements
      Since:
      5.0.0
    • flattenMany

      public static Collection flattenMany(Object[] self, Closure<?> transform)
      Flatten an array. This array and any nested arrays, collections or optionals have their contents (recursively) added to a new collection. A transform is applied to any leaf nodes before further flattening.
      Parameters:
      self - an array
      transform - a transform applied to any leaf elements
      Returns:
      a flattened Collection
      Since:
      5.0.0
    • getAt

      public static List<Boolean> getAt(boolean[] array, Range<?> range)
      Supports the subscript operator for a boolean array with a range giving the desired indices.
       boolean[] array = [false, true, false, true, false, true]
       assert array[2..<2] == [] // EmptyRange
       assert array[(0..5.5).step(2)] == [false, false, false] // NumberRange
       assert array[(1..5.5).step(2)] == [true, true, true]    // NumberRange
       
      Parameters:
      array - a boolean array
      range - a range indicating the indices for the items to retrieve
      Returns:
      list of the retrieved booleans
      Since:
      1.0
    • getAt

      public static List<Byte> getAt(byte[] array, Range<?> range)
      Supports the subscript operator for a byte array with a range giving the desired indices.
       byte[] 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
       
      Parameters:
      array - a byte array
      range - a range indicating the indices for the items to retrieve
      Returns:
      list of the retrieved bytes
      Since:
      1.0
    • getAt

      public static List<Character> getAt(char[] array, Range<?> range)
      Supports the subscript operator for a char array with a range giving the desired indices.
       char[] array = 'abcdef'.chars
       assert array[2..<2] == [] // EmptyRange
       assert array[(0..5.5).step(2)] == ['a', 'c', 'e']  // NumberRange
       assert array[(1..5.5).step(2)] == ['b', 'd', 'f']  // NumberRange
       
      Parameters:
      array - a char array
      range - a range indicating the indices for the items to retrieve
      Returns:
      list of the retrieved chars
      Since:
      1.5.0
    • getAt

      public static List<Short> getAt(short[] array, Range<?> range)
      Supports the subscript operator for a short array with a range giving the desired indices.
       short[] 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
       
      Parameters:
      array - a short array
      range - a range indicating the indices for the items to retrieve
      Returns:
      list of the retrieved shorts
      Since:
      1.0
    • getAt

      public static List<Integer> getAt(int[] array, Range<?> range)
      Supports 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
       
      Parameters:
      array - an int array
      range - a range indicating the indices for the items to retrieve
      Returns:
      list of the ints at the given indices
      Since:
      1.0
    • getAt

      public static List<Long> getAt(long[] array, 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:
      array - a long array
      range - a range indicating the indices for the items to retrieve
      Returns:
      list of the retrieved longs
      Since:
      1.0
    • getAt

      public static List<Float> getAt(float[] array, Range<?> range)
      Supports the subscript operator for a float array with a range giving the desired indices.
       float[] array = [1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f]
       assert array[2..<2] == [] // EmptyRange
       assert array[(0..5.5).step(2)] == [1.0f, 5.0f, 9.0f]   // NumberRange
       assert array[(1..5.5).step(2)] == [3.0f, 7.0f, 11.0f]  // NumberRange
       
      Parameters:
      array - a float array
      range - a range indicating the indices for the items to retrieve
      Returns:
      list of the retrieved floats
      Since:
      1.0
    • getAt

      public static List<Double> getAt(double[] array, Range<?> range)
      Supports the subscript operator for a double array with a range giving the desired indices.
       double[] array = [1.0d, 3.0d, 5.0d, 7.0d, 9.0d, 11.0d]
       assert array[2..<2] == [] // EmptyRange
       assert array[(0..5.5).step(2)] == [1.0d, 5.0d, 9.0d]   // NumberRange
       assert array[(1..5.5).step(2)] == [3.0d, 7.0d, 11.0d]  // NumberRange
       
      Parameters:
      array - a double array
      range - a range indicating the indices for the items to retrieve
      Returns:
      list of the retrieved doubles
      Since:
      1.0
    • getAt

      public static <T> List<T> getAt(T[] array, Range<?> range)
      Supports the subscript operator for an object array with a range giving the desired indices.
      Parameters:
      array - an Array of Objects
      range - a Range
      Returns:
      a range of a list from the range's from index up to but not including the range's to value
      Since:
      1.0
    • getAt

      public static List<Boolean> getAt(boolean[] array, IntRange range)
      Supports the subscript operator for a boolean array with an IntRange giving the desired indices.
       boolean[] array = [false, false, true, true, false]
       assert array[2..3] == [true, true]
       assert array[-2..-1] == [true, false]
       assert array[-1..-2] == [false, true]
       
      Parameters:
      array - a boolean array
      range - an IntRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved booleans
      Since:
      1.0
    • getAt

      public static List<Byte> getAt(byte[] array, IntRange range)
      Supports the subscript operator for a byte array with an IntRange giving the desired indices.
       byte[] array = [0, 10, 20, 30, 40]
       assert array[2..3] == [20, 30]
       assert array[-2..-1] == [30, 40]
       assert array[-1..-2] == [40, 30]
       
      Parameters:
      array - a byte array
      range - an IntRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved bytes
      Since:
      1.0
    • getAt

      public static List<Character> getAt(char[] array, IntRange range)
      Supports the subscript operator for a char array with an IntRange giving the desired indices.
       char[] array = 'abcdef'.chars
       assert array[2..3] == ['c', 'd']
       assert array[-2..-1] == ['e', 'f']
       assert array[-1..-2] == ['f', 'e']
       
      Parameters:
      array - a char array
      range - an IntRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved chars
      Since:
      1.0
    • getAt

      public static List<Short> getAt(short[] array, IntRange range)
      Supports the subscript operator for a short array with an IntRange giving the desired indices.
       short[] array = [0, 10, 20, 30, 40]
       assert array[2..3] == [20, 30]
       assert array[-2..-1] == [30, 40]
       assert array[-1..-2] == [40, 30]
       
      Parameters:
      array - a short array
      range - an IntRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved shorts
      Since:
      1.0
    • getAt

      public static List<Integer> getAt(int[] array, IntRange range)
      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]
       
      Parameters:
      array - an int array
      range - an IntRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved ints
      Since:
      1.0
    • getAt

      public static List<Long> getAt(long[] array, 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:
      array - a long array
      range - an IntRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved longs
      Since:
      1.0
    • getAt

      public static List<Float> getAt(float[] array, IntRange range)
      Supports the subscript operator for a float array with an IntRange giving the desired indices.
       float[] array = [0.0f, 10.0f, 20.0f, 30.0f, 40.0f]
       assert array[2..3] == [20.0f, 30.0f]
       assert array[-2..-1] == [30.0f, 40.0f]
       assert array[-1..-2] == [40.0f, 30.0f]
       
      Parameters:
      array - a float array
      range - an IntRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved floats
      Since:
      1.0
    • getAt

      public static List<Double> getAt(double[] array, IntRange range)
      Supports the subscript operator for a double array with an IntRange giving the desired indices.
       double[] array = [0.0d, 10.0d, 20.0d, 30.0d, 40.0d]
       assert array[2..3] == [20.0d, 30.0d]
       assert array[-2..-1] == [30.0d, 40.0d]
       assert array[-1..-2] == [40.0d, 30.0d]
       
      Parameters:
      array - a double array
      range - an IntRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved doubles
      Since:
      1.0
    • getAt

      public static <T> List<T> getAt(T[] array, IntRange range)
      Supports the subscript operator for an object array with an IntRange giving the desired indices.
      Parameters:
      array - an object array
      range - an IntRange
      Returns:
      a range of a list from the range's from index up to but not including the range's to value
      Since:
      1.0
    • getAt

      public static List<Boolean> getAt(boolean[] array, ObjectRange range)
      Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices.
       boolean[] array = [false, false, true, true, false]
       def range = new ObjectRange(2, 3)
       assert array[range] == [true, true]
       
      Parameters:
      array - a boolean array
      range - an ObjectRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved bytes
      Since:
      1.0
    • getAt

      public static List<Byte> getAt(byte[] array, ObjectRange range)
      Supports the subscript operator for a byte array with an ObjectRange giving the desired indices.
       byte[] array = [0, 10, 20, 30, 40]
       def range = new ObjectRange(2, 3)
       assert array[range] == [20, 30]
       
      Parameters:
      array - a byte array
      range - an ObjectRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved bytes
      Since:
      1.0
    • getAt

      public static List<Character> getAt(char[] array, ObjectRange range)
      Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices.
       char[] array = 'abcdef'.chars
       def range = new ObjectRange(2, 3)
       assert array[range] == ['c', 'd']
       
      Parameters:
      array - a char array
      range - an ObjectRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved chars
      Since:
      1.0
    • getAt

      public static List<Short> getAt(short[] array, ObjectRange range)
      Supports the subscript operator for a short array with an ObjectRange giving the desired indices.
       short[] array = [0, 10, 20, 30, 40]
       def range = new ObjectRange(2, 3)
       assert array[range] == [20, 30]
       
      Parameters:
      array - a short array
      range - an ObjectRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved shorts
      Since:
      1.0
    • getAt

      public static List<Integer> getAt(int[] array, ObjectRange range)
      Supports 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]
       
      Parameters:
      array - an int array
      range - an ObjectRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved ints
      Since:
      1.0
    • getAt

      public static List<Long> getAt(long[] array, 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:
      array - a long array
      range - an ObjectRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved longs
      Since:
      1.0
    • getAt

      public static List<Float> getAt(float[] array, ObjectRange range)
      Supports the subscript operator for a float array with an ObjectRange giving the desired indices.
       float[] array = [0.0f, 10.0f, 20.0f, 30.0f, 40.0f]
       def range = new ObjectRange(2, 3)
       assert array[range] == [20.0f, 30.0f]
       
      Parameters:
      array - a float array
      range - an ObjectRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved floats
      Since:
      1.0
    • getAt

      public static List<Double> getAt(double[] array, ObjectRange range)
      Supports the subscript operator for a double array with an ObjectRange giving the desired indices.
       double[] array = [0.0d, 10.0d, 20.0d, 30.0d, 40.0d]
       def range = new ObjectRange(2, 3)
       assert array[range] == [20.0d, 30.0d]
       
      Parameters:
      array - a double array
      range - an ObjectRange indicating the indices for the items to retrieve
      Returns:
      list of the retrieved doubles
      Since:
      1.0
    • getAt

      public static <T> List<T> getAt(T[] array, ObjectRange range)
      Supports the subscript operator for an object array with an ObjectRange giving the desired indices.
      Parameters:
      array - an Array of Objects
      range - an ObjectRange
      Returns:
      a range of a list from the range's from index up to but not including the range's to value
      Since:
      1.0
    • getAt

      public static <T> List<T> getAt(T[] array, EmptyRange<?> range)
      Supports the subscript operator for an object array with an EmptyRange.
      Parameters:
      array - an Array of Objects
      range - an EmptyRange
      Returns:
      an empty Range
      Since:
      1.5.0
    • getAt

      public static List<Boolean> getAt(boolean[] array, Collection<?> indices)
      Supports the subscript operator for a boolean array with a (potentially nested) collection giving the desired indices.
       boolean[] array = [false, false, true, true, false]
       assert array[2, 3] == [true, true]
       assert array[0, 0..1, [1, [-1]]] == [false, false, false, false, false]
       
      Parameters:
      array - a boolean array
      indices - a collection of indices for the items to retrieve
      Returns:
      list of the booleans at the given indices
      Since:
      1.0
    • getAt

      public static List<Byte> getAt(byte[] array, Collection<?> indices)
      Supports the subscript operator for a byte array with a (potentially nested) collection giving the desired indices.
       byte[] array = [0, 2, 4, 6, 8]
       assert array[2, 3] == [4, 6]
       assert array[1, 0..1, [0, [-1]]] == [2, 0, 2, 0, 8]
       
      Parameters:
      array - a byte array
      indices - a collection of indices for the items to retrieve
      Returns:
      list of the bytes at the given indices
      Since:
      1.0
    • getAt

      public static List<Character> getAt(char[] array, Collection<?> indices)
      Supports the subscript operator for a char array with a (potentially nested) collection giving the desired indices.
       char[] array = 'abcde'.chars
       assert array[2, 3] == ['c', 'd']
       assert array[1, 0..1, [0, [-1]]] == ['b', 'a', 'b', 'a', 'e']
       
      Parameters:
      array - a char array
      indices - a collection of indices for the items to retrieve
      Returns:
      list of the chars at the given indices
      Since:
      1.0
    • getAt

      public static List<Short> getAt(short[] array, Collection<?> indices)
      Supports the subscript operator for a short array with a (potentially nested) collection giving the desired indices.
       short[] array = [0, 2, 4, 6, 8]
       assert array[2, 3] == [4, 6]
       assert array[1, 0..1, [0, [-1]]] == [2, 0, 2, 0, 8]
       
      Parameters:
      array - a short array
      indices - a collection of indices for the items to retrieve
      Returns:
      list of the shorts at the given indices
      Since:
      1.0
    • getAt

      public static List<Integer> getAt(int[] array, Collection<?> indices)
      Supports 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]
       
      Parameters:
      array - an int array
      indices - a collection of indices for the items to retrieve
      Returns:
      list of the ints at the given indices
      Since:
      1.0
    • getAt

      public static List<Long> getAt(long[] array, 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:
      array - a long array
      indices - a collection of indices for the items to retrieve
      Returns:
      list of the longs at the given indices
      Since:
      1.0
    • getAt

      public static List<Float> getAt(float[] array, Collection<?> indices)
      Supports the subscript operator for a float array with a (potentially nested) collection giving the desired indices.
       float[] array = [0.0f, 2.0f, 4.0f, 6.0f, 8.0f]
       assert array[2, 3] == [4.0f, 6.0f]
       assert array[1, 0..1, [0, [-1]]] == [2.0f, 0.0f, 2.0f, 0.0f, 8.0f]
       
      Parameters:
      array - a float array
      indices - a collection of indices for the items to retrieve
      Returns:
      list of the floats at the given indices
      Since:
      1.0
    • getAt

      public static List<Double> getAt(double[] array, Collection<?> indices)
      Supports the subscript operator for a double array with a (potentially nested) collection giving the desired indices.
       double[] array = [0.0d, 2.0d, 4.0d, 6.0d, 8.0d]
       assert array[2, 3] == [4.0d, 6.0d]
       assert array[1, 0..1, [0, [-1]]] == [2.0d, 0.0d, 2.0d, 0.0d, 8.0d]
       
      Parameters:
      array - a double array
      indices - a collection of indices for the items to retrieve
      Returns:
      list of the doubles at the given indices
      Since:
      1.0
    • getAt

      public static <T> List<T> getAt(T[] array, Collection<?> indices)
      Selects a List of items from an array using a Collection to identify the indices to be selected.
      Parameters:
      array - an object array
      indices - a collection of indices
      Returns:
      a new list of the values at the given indices
      Since:
      1.0
    • getIndices

      public static IntRange getIndices(boolean[] self)
      Returns indices of the boolean array.
       boolean[] array = [false, true]
       assert array.indices == 0..1
       
      Since:
      3.0.8
      See Also:
    • getIndices

      public static IntRange getIndices(byte[] self)
      Returns indices of the byte array.
       byte[] array = [0, 1]
       assert array.indices == 0..1
       
      Since:
      3.0.8
      See Also:
    • getIndices

      public static IntRange getIndices(char[] self)
      Returns indices of the char array.
       char[] array = 'ab'.chars
       assert array.indices == 0..1
       
      Since:
      3.0.8
      See Also:
    • getIndices

      public static IntRange getIndices(short[] self)
      Returns indices of the short array.
       short[] array = [0, 1]
       assert array.indices == 0..1
       
      Since:
      3.0.8
      See Also:
    • getIndices

      public static IntRange getIndices(int[] self)
      Returns indices of the int array.
       int[] array = [0, 1]
       assert array.indices == 0..1
       
      Since:
      3.0.8
      See Also:
    • getIndices

      public static IntRange getIndices(long[] self)
      Returns indices of the long array.
       long[] array = [0L, 1L]
       assert array.indices == 0..1
       
      Since:
      3.0.8
      See Also:
    • getIndices

      public static IntRange getIndices(float[] self)
      Returns indices of the float array.
       float[] array = [0.0f, 1.0f]
       assert array.indices == 0..1
       
      Since:
      3.0.8
      See Also:
    • getIndices

      public static IntRange getIndices(double[] self)
      Returns indices of the double array.
       double[] array = [0.0d, 1.0d]
       assert array.indices == 0..1
       
      Since:
      3.0.8
      See Also:
    • getIndices

      public static <T> IntRange getIndices(T[] self)
      Returns indices of the array.

      Example:

       String[] letters = ['a', 'b', 'c', 'd']
       assert 0..<4 == letters.indices
       
      Parameters:
      self - an array
      Returns:
      an index range
      Since:
      2.4.0
    • grep

      public static <T> List<T> grep(T[] self)
      Iterates over the array 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] as Object[]
       assert items.grep() == [1, 2, true, 'foo', [4, 5]]
       
      Parameters:
      self - an array
      Returns:
      a list of elements which satisfy Groovy truth
      Since:
      2.0
      See Also:
    • grep

      public static <T> List<T> grep(T[] self, Object filter)
      Iterates over the array of items and returns a collection of items that match the given filter - calling the DefaultGroovyMethods.isCase(Object,Object) method used by switch statements. This method can be used with different kinds of filters like regular expressions, classes, ranges etc. Example:
       def items = ['a', 'b', 'aa', 'bc', 3, 4.5] as Object[]
       assert items.grep( ~/a+/ )  == ['a', 'aa']
       assert items.grep( ~/../ )  == ['aa', 'bc']
       assert items.grep( Number ) == [ 3, 4.5 ]
       assert items.grep{ it.toString().size() == 1 } == [ 'a', 'b', 3 ]
       
      Parameters:
      self - an array
      filter - the filter to perform on each element of the array (using the DefaultGroovyMethods.isCase(java.lang.Object, java.lang.Object) method)
      Returns:
      a list of objects which match the filter
      Since:
      2.0
    • groupBy

      public static <K, T> Map<K,List<T>> groupBy(T[] self, @ClosureParams(Component.class) Closure<K> closure)
      Sorts all array members into groups determined by the supplied mapping closure. The closure should return the key that this item should be grouped by. The returned LinkedHashMap will have an entry for each distinct key returned from the closure, with each value being a list of items for that group.

      Example usage:

       Integer[] items = [1,2,3,4,5,6]
       assert [0:[2,4,6], 1:[1,3,5]] == items.groupBy { it % 2 }
       
      Parameters:
      self - an array to group
      closure - a closure mapping entries on keys
      Returns:
      A map grouped by keys.
      Since:
      2.2.0
    • groupBy

      public static Map groupBy(Object[] self, Object... closures)
      Sorts all array members into (sub)groups determined by the supplied mapping closures as per the Iterable variant of this method.
      Parameters:
      self - an array to group
      closures - an array of closures, each mapping entries on keys
      Returns:
      A map grouped by keys on each criterion.
      Since:
      2.2.0
    • groupBy

      public static Map groupBy(Object[] self, List<Closure<?>> closures)
      Sorts all array members into (sub)groups determined by the supplied mapping closures as per the list variant of this method.
      Parameters:
      self - an array to group
      closures - a list of closures, each mapping entries on keys
      Returns:
      A map grouped by keys on each criterion.
      Since:
      2.2.0
    • head

      public static boolean head(boolean[] self)
      Returns the first item from the boolean array.
       boolean[] array = [true, false]
       assert array.head() == true
       
      An alias for first().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • head

      public static byte head(byte[] self)
      Returns the first item from the byte array.
       byte[] bytes = [1, 2, 3]
       assert bytes.head() == 1
       
      An alias for first().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • head

      public static char head(char[] self)
      Returns the first item from the char array.
       char[] chars = ['a', 'b', 'c']
       assert chars.head() == 'a'
       
      An alias for first().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • head

      public static short head(short[] self)
      Returns the first item from the short array.
       short[] shorts = [10, 20, 30]
       assert shorts.head() == 10
       
      An alias for first().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • head

      public static int head(int[] self)
      Returns the first item from the int array.
       int[] ints = [1, 3, 5]
       assert ints.head() == 1
       
      An alias for first().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • head

      public static long head(long[] self)
      Returns the first item from the long array.
       long[] longs = [2L, 4L, 6L]
       assert longs.head() == 2L
       
      An alias for first().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • head

      public static float head(float[] self)
      Returns the first item from the float array.
       float[] floats = [2.0f, 4.0f, 6.0f]
       assert floats.head() == 2.0f
       
      An alias for first().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • head

      public static double head(double[] self)
      Returns the first item from the double array.
       double[] doubles = [10.0d, 20.0d, 30.0d]
       assert doubles.head() == 10.0d
       
      An alias for first().
      Parameters:
      self - an array
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • head

      public static <T> T head(T[] self)
      Returns the first item from the Object array.
      def array = [3, 4, 2].toArray()
       assert array.head() == 3
      Parameters:
      self - an array
      Returns:
      the first item from the Object array
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      1.7.3
    • indexed

      public static Map<Integer,Integer> indexed(int[] self)
      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()
       
      Since:
      3.0.8
      See Also:
    • indexed

      public static Map<Integer,Long> indexed(long[] self)
      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:
    • indexed

      public static Map<Integer,Double> indexed(double[] self)
      Zips a double[] with indices in (index, value) order starting from index 0.

      Example usage:

       double[] nums = [10.0d, 20.0d, 30.0d]
       assert [0: 10.0d, 1: 20.0d, 2: 30.0d] == nums.indexed()
       
      Since:
      3.0.8
      See Also:
    • indexed

      public static Map<Integer,Integer> indexed(int[] self, int offset)
      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" }
       
      Parameters:
      self - an Iterable
      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:
    • indexed

      public static Map<Integer,Long> indexed(long[] self, 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:
      self - a long[]
      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:
    • indexed

      public static Map<Integer,Double> indexed(double[] self, int offset)
      Zips a double[] with indices in (index, value) order.

      Example usage:

       double[] nums = [10.0d, 20.0d, 30.0d]
       assert [5: 10.0d, 6: 20.0d, 7: 30.0d] == nums.indexed(5)
       
      Parameters:
      self - a double[]
      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:
    • init

      public static boolean[] init(boolean[] self)
      Returns the items from the boolean array excluding the last item.
       boolean[] array = [true, false, true]
       def result = array.init()
       assert result == [true, false]
       assert array.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • init

      public static byte[] init(byte[] self)
      Returns the items from the byte array excluding the last item.
       byte[] bytes = [1, 2, 3]
       def result = bytes.init()
       assert result == [1, 2]
       assert bytes.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • init

      public static char[] init(char[] self)
      Returns the items from the char array excluding the last item.
       char[] chars = ['a', 'b', 'c']
       def result = chars.init()
       assert result == ['a', 'b']
       assert chars.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • init

      public static short[] init(short[] self)
      Returns the items from the short array excluding the last item.
       short[] shorts = [10, 20, 30]
       def result = shorts.init()
       assert result == [10, 20]
       assert shorts.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • init

      public static int[] init(int[] self)
      Returns 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
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • init

      public static long[] init(long[] self)
      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
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • init

      public static float[] init(float[] self)
      Returns the items from the float array excluding the last item.
       float[] floats = [2.0f, 4.0f, 6.0f]
       def result = floats.init()
       assert result == [2.0f, 4.0f]
       assert floats.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • init

      public static double[] init(double[] self)
      Returns the items from the double array excluding the last item.
       double[] doubles = [10.0d, 20.0d, 30.0d]
       def result = doubles.init()
       assert result == [10.0d, 20.0d]
       assert doubles.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • init

      public static <T> T[] init(T[] self)
      Returns the items from the Object array excluding the last item.
           String[] strings = ["a", "b", "c"]
           def result = strings.init()
           assert result.length == 2
           assert strings.class.componentType == String
       
      Parameters:
      self - an array
      Returns:
      an array without its last element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      2.4.0
    • inject

      public static <E, T, V extends T> T inject(E[] self, @ClosureParams(value=FromString.class,options="E,E") Closure<V> closure)
      Iterates through the given array as with inject(Object[],initialValue,closure), but using the first element of the array as the initialValue, and then iterating the remaining elements of the array.
      Parameters:
      self - an array
      closure - a closure
      Returns:
      the result of the last closure call
      Throws:
      NoSuchElementException - if the array is empty.
      Since:
      1.8.7
      See Also:
    • inject

      public static <E, T, U extends T, V extends T> T inject(E[] self, U initialValue, @ClosureParams(value=FromString.class,options="U,E") Closure<V> closure)
      Iterates through the given array, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until all elements of the array have been used.

      Also known as foldLeft in functional parlance.

      Parameters:
      self - an Object[]
      initialValue - some initial value
      closure - a closure
      Returns:
      the result of the last closure call
      Since:
      1.5.0
    • iterator

      public static <T> Iterator<T> iterator(T[] self)
      Returns an Iterator which traverses the given array in index order.
      Parameters:
      self - an array
      Returns:
      an Iterator backed by the given Array.
      Since:
      1.6.4
      See Also:
    • join

      public static String join(boolean[] self)
      Concatenates the string representation of each item in this array.
      Parameters:
      self - an array of boolean
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(byte[] self)
      Concatenates the string representation of each item in this array.
      Parameters:
      self - an array of byte
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(char[] self)
      Concatenates the string representation of each item in this array.
      Parameters:
      self - an array of char
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(short[] self)
      Concatenates the string representation of each item in this array.
      Parameters:
      self - an array of short
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(int[] self)
      Concatenates the string representation of each item in this array.
      Parameters:
      self - an array of int
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(long[] self)
      Concatenates the string representation of each item in this array.
      Parameters:
      self - an array of long
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(float[] self)
      Concatenates the string representation of each item in this array.
      Parameters:
      self - an array of float
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(double[] self)
      Concatenates the string representation of each item in this array.
      Parameters:
      self - an array of double
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(Object[] self)
      Concatenates the string representation of each item in this array.
       def array = new Number[]{1,2L,3G}
       assert array.join() == "123"
       
      Parameters:
      self - an array of Object
      Returns:
      the joined String
      Since:
      5.0.0
    • join

      public static String join(boolean[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
      Parameters:
      self - an array of boolean
      separator - a String separator
      Returns:
      the joined String
      Since:
      2.4.1
    • join

      public static String join(byte[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
      Parameters:
      self - an array of byte
      separator - a String separator
      Returns:
      the joined String
      Since:
      2.4.1
    • join

      public static String join(char[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
      Parameters:
      self - an array of char
      separator - a String separator
      Returns:
      the joined String
      Since:
      2.4.1
    • join

      public static String join(short[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
      Parameters:
      self - an array of short
      separator - a String separator
      Returns:
      the joined String
      Since:
      2.4.1
    • join

      public static String join(int[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
      Parameters:
      self - an array of int
      separator - a String separator
      Returns:
      the joined String
      Since:
      2.4.1
    • join

      public static String join(long[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
      Parameters:
      self - an array of long
      separator - a String separator
      Returns:
      the joined String
      Since:
      2.4.1
    • join

      public static String join(float[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
      Parameters:
      self - an array of float
      separator - a String separator
      Returns:
      the joined String
      Since:
      2.4.1
    • join

      public static String join(double[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
      Parameters:
      self - an array of double
      separator - a String separator
      Returns:
      the joined String
      Since:
      2.4.1
    • join

      public static String join(Object[] self, String separator)
      Concatenates the string representation of each item in this array, with the given String as a separator between each item.
       Serializable[] array = [1,2L,-3G]
       assert array.join("+") == "1+2+-3"
       
      Parameters:
      self - an array of Object
      separator - a String separator
      Returns:
      the joined String
      Since:
      1.0
    • last

      public static boolean last(boolean[] self)
      Returns the last item from the boolean array.
       boolean[] array = [true, false, true]
       assert array.last() == true
       
      Parameters:
      self - an array
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • last

      public static byte last(byte[] self)
      Returns the last item from the byte array.
       byte[] bytes = [1, 2, 3]
       assert bytes.last() == 3
       
      Parameters:
      self - an array
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • last

      public static char last(char[] self)
      Returns the last item from the char array.
       char[] chars = ['a', 'b', 'c']
       assert chars.last() == 'c'
       
      Parameters:
      self - an array
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • last

      public static short last(short[] self)
      Returns the last item from the short array.
       short[] shorts = [10, 20, 30]
       assert shorts.last() == 30
       
      Parameters:
      self - an array
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • last

      public static int last(int[] self)
      Returns the last item from the int array.
       int[] ints = [1, 3, 5]
       assert ints.last() == 5
       
      Parameters:
      self - an array
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • last

      public static long last(long[] self)
      Returns the last item from the long array.
       long[] longs = [2L, 4L, 6L]
       assert longs.last() == 6L
       
      Parameters:
      self - an array
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • last

      public static float last(float[] self)
      Returns the last item from the float array.
       float[] floats = [2.0f, 4.0f, 6.0f]
       assert floats.last() == 6.0f
       
      Parameters:
      self - an array
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • last

      public static double last(double[] self)
      Returns the last item from the double array.
       double[] doubles = [10.0d, 20.0d, 30.0d]
       assert doubles.last() == 30.0d
       
      Parameters:
      self - an array
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the array is empty
      Since:
      5.0.0
    • last

      public static <T> T last(T[] self)
      Returns the last item from the array.
       def array = [3, 4, 2].toArray()
       assert array.last() == 2
       
      Parameters:
      self - an array
      Returns:
      the last item from the array
      Throws:
      NoSuchElementException - if you try to access last() for an empty array
      Since:
      1.7.3
    • max

      public static int max(int[] self)
      Adds max() method to int arrays.

      Example usage:

       int[] nums = [1, 3, 2]
       assert 3 == nums.max()
       
      Parameters:
      self - an int array
      Returns:
      the maximum value
      Since:
      3.0.8
    • max

      public static long max(long[] self)
      Adds max() method to long arrays.

      Example usage:

       long[] nums = [1L, 3L, 2L]
       assert 3L == nums.max()
       
      Parameters:
      self - a long array
      Returns:
      the maximum value
      Since:
      3.0.8
    • max

      public static double max(double[] self)
      Adds max() method to double arrays.

      Example usage:

       double[] nums = [1.1d, 3.3d, 2.2d]
       assert 3.3d == nums.max()
       
      Parameters:
      self - a double array
      Returns:
      the maximum value
      Since:
      3.0.8
    • max

      public static <T> T max(T[] self)
      Adds max() method to Object arrays.
      Parameters:
      self - an array
      Returns:
      the maximum value
      Since:
      1.5.5
      See Also:
    • max

      @Incubating public static int max(int[] self, 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[] nums = [10, 20, -30]
       assert 20 == nums.max{ n, m -> n <=> m }
       assert -30 == nums.max{ n, m -> n.abs() <=> m.abs() }
       

      Parameters:
      self - an int array
      comparator - a comparator, i.e. returns a negative value if the first parameter is less than the second
      Returns:
      the maximum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • max

      @Incubating public static int max(int[] self, IntUnaryOperator operator)
      Selects 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() }
       

      Parameters:
      self - an int array
      operator - an operator that returns an int used for comparing values
      Returns:
      the maximum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • max

      @Incubating public static long max(long[] self, 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:
      self - a long array
      comparator - a comparator, i.e. returns a negative value if the first parameter is less than the second
      Returns:
      the maximum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • max

      @Incubating public static long max(long[] self, 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:
      self - a long array
      operator - an operator that returns a long used for comparing values
      Returns:
      the maximum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • max

      @Incubating public static double max(double[] self, DoubleComparator comparator)
      Selects the maximum value found from the double array using the supplier DoubleComparator to determine the maximum of any two values.

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

      Parameters:
      self - a double array
      comparator - a comparator, i.e. returns a negative value if the first parameter is less than the second
      Returns:
      the maximum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • max

      @Incubating public static double max(double[] self, DoubleUnaryOperator operator)
      Selects the maximum value found from the double array using the supplier DoubleUnaryOperator to determine the maximum of any two values. The operator is applied to each array element and the results are compared.

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

      Parameters:
      self - a double array
      operator - an operator that returns a double used for comparing values
      Returns:
      the maximum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • max

      public static <T> T max(T[] self, Comparator<? super T> comparator)
      Selects the maximum value found from the Object array using the given comparator.
      Parameters:
      self - an array
      comparator - a Comparator
      Returns:
      the maximum value
      Since:
      1.5.5
      See Also:
    • max

      public static <T> T max(T[] self, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure)
      Selects the maximum value found from the Object array using the closure to determine the correct ordering.

      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:
      self - an array
      closure - a Closure used to determine the correct ordering
      Returns:
      the maximum value
      Since:
      1.5.5
    • maxBy

      @Incubating public static int maxBy(int[] self, @ClosureParams(Component.class) Closure<?> closure)
      Selects 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.

      Parameters:
      self - an int array
      closure - a Closure used to determine the correct ordering
      Returns:
      the maximum value
      Since:
      5.0.0
      See Also:
    • maxBy

      @Incubating public static long maxBy(long[] self, @ClosureParams(Component.class) 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:
      self - a long array
      closure - a Closure used to determine the correct ordering
      Returns:
      the maximum value
      Since:
      5.0.0
      See Also:
    • maxBy

      @Incubating public static double maxBy(double[] self, @ClosureParams(Component.class) Closure<?> closure)
      Selects the maximum value found from the double array using the closure to determine the maximum of any two values.

       double[] nums = [-30.0d, 10.0d, 20.0d]
       assert 20.0d == nums.maxBy{ a, b -> a <=> b }
       assert -30.0d == 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:
      self - a double array
      closure - a Closure used to determine the correct ordering
      Returns:
      the maximum value
      Since:
      5.0.0
      See Also:
    • maxComparing

      @Incubating public static int maxComparing(int[] self, Comparator<Integer> comparator)
      Selects 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())
       

      Parameters:
      self - an int array
      comparator - a Comparator
      Returns:
      the maximum value
      Since:
      5.0.0
      See Also:
    • maxComparing

      @Incubating public static long maxComparing(long[] self, Comparator<Long> 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:
      self - a long array
      comparator - a Comparator
      Returns:
      the maximum value
      Since:
      5.0.0
      See Also:
    • maxComparing

      @Incubating public static double maxComparing(double[] self, Comparator<Double> comparator)
      Selects the maximum value found from the double array using the comparator to determine the maximum of any two values.

       double[] nums = [10.0d, 20.0d, 30.0d]
       assert 30d == nums.maxComparing(Comparator.naturalOrder())
       assert 10d == nums.maxComparing(Comparator.reverseOrder())
       

      Parameters:
      self - a double array
      comparator - a Comparator
      Returns:
      the maximum value
      Since:
      5.0.0
      See Also:
    • min

      public static int min(int[] self)
      Adds min() method to int arrays.

      Example usage:

       int[] nums = [20, 10, 30]
       assert 10 == nums.min()
       
      Parameters:
      self - an int array
      Returns:
      the minimum value
      Since:
      3.0.8
    • min

      public static long min(long[] self)
      Adds min() method to long arrays.

      Example usage:

       long[] nums = [20L, 10L, 30L]
       assert 10L == nums.min()
       
      Parameters:
      self - a long array
      Returns:
      the minimum value
      Since:
      3.0.8
    • min

      public static double min(double[] self)
      Adds min() method to double arrays.

      Example usage:

       double[] nums = [20.0d, 10.0d, 30.0d]
       assert 10.0d == nums.min()
       
      Parameters:
      self - a double array
      Returns:
      the minimum value
      Since:
      3.0.8
    • min

      public static <T> T min(T[] self)
      Adds min() method to Object arrays.
      Parameters:
      self - an array
      Returns:
      the minimum value
      Since:
      1.5.5
      See Also:
    • min

      @Incubating public static int min(int[] self, IntComparator comparator)
      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() }
       

      Parameters:
      self - an int array
      comparator - a comparator, i.e. returns a negative value if the first parameter is less than the second
      Returns:
      the minimum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • min

      @Incubating public static int min(int[] self, IntUnaryOperator operator)
      Selects 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() }
       

      Parameters:
      self - an int array
      operator - an operator that returns an int used for comparing values
      Returns:
      the minimum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • min

      @Incubating public static long min(long[] self, 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:
      self - a long array
      comparator - a comparator, i.e. returns a negative value if the first parameter is less than the second
      Returns:
      the minimum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • min

      @Incubating public static long min(long[] self, 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:
      self - a long array
      operator - an operator that returns a long used for comparing values
      Returns:
      the minimum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • min

      @Incubating public static double min(double[] self, DoubleComparator comparator)
      Selects the minimum value found from the double array using the supplier DoubleBinaryOperator as a comparator to determine the minimum of any two values.

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

      Parameters:
      self - a double array
      comparator - a comparator, i.e. returns a negative value if the first parameter is less than the second
      Returns:
      the minimum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • min

      @Incubating public static double min(double[] self, DoubleUnaryOperator operator)
      Selects the minimum value found from the double array using the supplier DoubleUnaryOperator to determine the minimum of any two values. The operator is applied to each array element and the results are compared.

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

      Parameters:
      self - a double array
      operator - an operator that returns a double used for comparing values
      Returns:
      the minimum value
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • min

      public static <T> T min(T[] self, Comparator<? super T> comparator)
      Selects the minimum value found from the Object array using the given comparator.
      Parameters:
      self - an array
      comparator - a Comparator
      Returns:
      the minimum value
      Since:
      1.5.5
      See Also:
    • min

      public static <T> T min(T[] self, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure)
      Selects the minimum value found from the Object array using the closure to determine the correct ordering.

      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:
      self - an array
      closure - a Closure used to determine the correct ordering
      Returns:
      the minimum value
      Since:
      1.5.5
      See Also:
    • minBy

      @Incubating public static int minBy(int[] self, @ClosureParams(Component.class) Closure<?> closure)
      Selects 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.

      Parameters:
      self - an int array
      closure - a Closure used to determine the correct ordering
      Returns:
      the minimum value
      Since:
      5.0.0
      See Also:
    • minBy

      @Incubating public static long minBy(long[] self, @ClosureParams(Component.class) 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:
      self - a long array
      closure - a Closure used to determine the correct ordering
      Returns:
      the minimum value
      Since:
      5.0.0
      See Also:
    • minBy

      @Incubating public static double minBy(double[] self, @ClosureParams(Component.class) Closure<?> closure)
      Selects the minimum value found from the double array using the closure to determine the minimum of any two values.

       double[] nums = [-20.0d, 10.0d, 30.0d]
       assert -20.0d == nums.minBy{ a, b -> a <=> b }
       assert 10.0d == 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 double) which is then used for further comparison.

      Parameters:
      self - a double array
      closure - a Closure used to determine the correct ordering
      Returns:
      the minimum value
      Since:
      5.0.0
      See Also:
    • minComparing

      @Incubating public static int minComparing(int[] self, Comparator<Integer> comparator)
      Selects 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())
       

      Parameters:
      self - an int array
      comparator - a Comparator
      Returns:
      the minimum value
      Since:
      5.0.0
      See Also:
    • minComparing

      @Incubating public static long minComparing(long[] self, Comparator<Long> 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:
      self - a long array
      comparator - a Comparator
      Returns:
      the minimum value
      Since:
      5.0.0
      See Also:
    • minComparing

      @Incubating public static double minComparing(double[] self, Comparator<Double> comparator)
      Selects the minimum value found from the double array using the comparator to determine the minimum of any two values.

       double[] nums = [10.0d, 20.0d, 30.0d]
       assert 10d == nums.minComparing(Comparator.naturalOrder())
       assert 30d == nums.minComparing(Comparator.reverseOrder())
       

      Parameters:
      self - a double array
      comparator - a Comparator
      Returns:
      the minimum value
      Since:
      5.0.0
      See Also:
    • minus

      public static <T> T[] minus(T[] self, Iterable<?> removeMe)
      Creates a new array composed of the elements of the first array minus the elements of the given Iterable.
       Integer[] ints = [1, 2, 3, 1]
       List<Integer> nope = [1, 3]
       def result = ints - nope
       assert result.class == Integer[]
       assert result == new Integer[]{2}
      
       Integer[] none = []
       result = none - 123
       assert result !== none
       assert result.length == 0
       assert result.class == Integer[]
       
      Parameters:
      self - an array
      removeMe - an Iterable of elements to remove
      Returns:
      An array with the supplied elements removed.
      Since:
      1.5.5
    • minus

      public static <T> T[] minus(T[] self, Object[] removeMe)
      Creates a new array composed of the elements of the first array minus the elements of the given array.
       Integer[] ints = [1, 2, 3, 1]
       Integer[] nope = [1, 3]
       def result = ints - nope
       assert result.class == Integer[]
       assert result == new Integer[]{2}
      
       Integer[] none = []
       result = none - 123
       assert result !== none
       assert result.length == 0
       assert result.class == Integer[]
       
      Parameters:
      self - an array
      removeMe - an array of elements to remove
      Returns:
      An array with the supplied elements removed.
      Since:
      1.5.5
    • minus

      public static <T> T[] minus(T[] self, Object removeMe)
      Creates a new array composed of the elements of the given array minus every occurrence the given object.
       Integer[] ints = [1, 2, 3, 1]
       def result = ints - 1
       assert result.class == Integer[]
       assert result == new Integer[]{2, 3}
      
       Integer[] none = []
       result = none - '1'
       assert result !== none
       assert result.length == 0
       assert result.class == Integer[]
       
      Parameters:
      self - an array
      removeMe - an element to remove from the array
      Returns:
      a new array with the operand removed
      Since:
      1.5.5
    • plus

      public static <T> T[] plus(T[] left, Collection<?> right)
      Creates an array containing elements from an original array plus those from a Collection.
       Integer[] a = [1, 2, 3]
       def result = a + [4, 5, 6]
       assert result.class == Integer[]
       assert result == new Integer[]{1, 2, 3, 4, 5, 6}
      
       Number[] c = [-1, 0.9, null]
       result = c + [1, 2, 3]
       assert result.class == Number[]
       assert result == new Number[]{-1, 0.9, null, 1, 2, 3}
      
       result = a + [-1, 0.9, null]
       assert result.class == Integer[]
       assert result == new Integer[]{1, 2, 3, -1, 0, null}
      
       // improper type arguments; Date can't be coerced to Integer
       groovy.test.GroovyAssert.shouldFail(ClassCastException) { a + [new Date()] }
       
      Parameters:
      left - the array
      right - a Collection to be appended
      Returns:
      A new array containing left with right appended to it.
      Throws:
      ClassCastException - if any elements from right aren't compatible (according to DefaultTypeTransformation.castToType(Object, Class)) to the component type of left
      Since:
      1.8.7
    • plus

      public static <T> T[] plus(T[] left, Iterable<?> right)
      Creates an array containing elements from an original array plus those from an Iterable.
       class AbcIterable implements Iterable {
           Iterator iterator() { "abc".iterator() }
       }
       String[] array = ['x', 'y', 'z']
       def result = array + new AbcIterable()
       assert result.class == String[]
       assert result == new String[]{'x', 'y', 'z', 'a', 'b', 'c'}
       
      Parameters:
      left - the array
      right - an Iterable to be appended
      Returns:
      A new array containing elements from left with those from right appended.
      Throws:
      ClassCastException - if any elements from right aren't compatible (according to DefaultTypeTransformation.castToType(Object, Class)) to the component type of left
      Since:
      1.8.7
      See Also:
    • plus

      public static <T> T[] plus(T[] left, Object[] right)
      Creates an array as a union of two arrays.
       Integer[] a = [1, 2, 3]
       Integer[] b = [4, 5, 6]
       def result = a + b
       assert result.class == Integer[]
       assert result == new Integer[]{1, 2, 3, 4, 5, 6}
      
       Number[] c = [-1, 0.9, null]
       result = c + a
       assert result.class == Number[]
       assert result == new Number[]{-1, 0.9, null, 1, 2, 3}
      
       result = a + c
       assert result.class == Integer[]
       assert result == new Integer[]{1, 2, 3, -1, 0, null}
      
       Date[] d = [new Date()]
       // improper type arguments; Date can't be coerced to Integer
       groovy.test.GroovyAssert.shouldFail(ClassCastException) { a + d }
       
      Parameters:
      left - the left Array
      right - the right Array
      Returns:
      A new array containing right appended to left.
      Throws:
      ClassCastException - if any elements from right aren't compatible (according to DefaultTypeTransformation.castToType(Object, Class)) to the component type of left
      Since:
      1.8.7
    • plus

      public static <T> T[] plus(T[] left, Object right)
      Creates an array containing elements from an original array plus an additional appended element.
       Integer[] a = [1, 2, 3]
       def result = a + 4
       assert result.class == Integer[]
       assert result == new Integer[]{1, 2, 3, 4}
      
       result = a + 5.5d
       assert result.class == Integer[]
       assert result == new Integer[]{1, 2, 3, 5}
      
       // improper type arguments; Date can't be coerced to Integer
       groovy.test.GroovyAssert.shouldFail(ClassCastException) { a + new Date() }
       
      Parameters:
      left - the array
      right - the value to append
      Returns:
      A new array containing left with right appended to it.
      Throws:
      ClassCastException - if any elements from right aren't compatible (according to DefaultTypeTransformation.castToType(Object, Class)) to the component type of left
      Since:
      1.8.7
    • reverse

      public static boolean[] reverse(boolean[] self)
      Creates a new boolean array containing items which are the same as this array but in reverse order.
       boolean[] array = [false, true]
       assert array.reverse() == [true, false]
       
      Parameters:
      self - a boolean array
      Returns:
      an array containing the reversed items
      Since:
      5.0.0
      See Also:
    • reverse

      public static boolean[] reverse(boolean[] self, 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.
       boolean[] array = [false, true, true]
       def yarra = array.reverse(true)
       assert array == [true, true, false]
       assert yarra == [true, true, false]
       assert array === yarra
       yarra = array.reverse(false)
       assert array !== yarra
       assert array == [true, true, false]
       assert yarra == [false, true, true]
       
      Parameters:
      self - a boolean array
      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
    • reverse

      public static byte[] reverse(byte[] self)
      Creates a new byte array containing items which are the same as this array but in reverse order.
       byte[] array = 1..2
       assert array.reverse() == 2..1
       
      Parameters:
      self - a byte array
      Returns:
      an array containing the reversed items
      Since:
      5.0.0
      See Also:
    • reverse

      public static byte[] reverse(byte[] self, 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.
       byte[] 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
       
      Parameters:
      self - a byte array
      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
    • reverse

      public static char[] reverse(char[] self)
      Creates a new char array containing items which are the same as this array but in reverse order.
       char[] array = ['a', 'b']
       assert array.reverse() == ['b', 'a'] as char[]
       
      Parameters:
      self - a char array
      Returns:
      an array containing the reversed items
      Since:
      5.0.0
      See Also:
    • reverse

      public static char[] reverse(char[] self, 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.
       char[] array = ['a', 'b', 'c']
       def yarra = array.reverse(true)
       assert array == ['c', 'b', 'a']
       assert yarra == ['c', 'b', 'a']
       assert array === yarra
       yarra = array.reverse(false)
       assert array !== yarra
       assert array == ['c', 'b', 'a']
       assert yarra == ['a', 'b', 'c']
       
      Parameters:
      self - a char array
      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
    • reverse

      public static short[] reverse(short[] self)
      Creates a new short array containing items which are the same as this array but in reverse order.
       short[] array = 1..2
       assert array.reverse() == 2..1
       
      Parameters:
      self - a short array
      Returns:
      an array containing the reversed items
      Since:
      5.0.0
      See Also:
    • reverse

      public static short[] reverse(short[] self, 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.
       short[] 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
       
      Parameters:
      self - a short array
      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
    • reverse

      public static int[] reverse(int[] self)
      Creates 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
       
      Parameters:
      self - an int array
      Returns:
      an array containing the reversed items
      Since:
      5.0.0
      See Also:
    • reverse

      public static int[] reverse(int[] self, 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.
       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
       
      Parameters:
      self - an int array
      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
    • reverse

      public static long[] reverse(long[] self)
      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
       
      Parameters:
      self - a long array
      Returns:
      an array containing the reversed items
      Since:
      5.0.0
      See Also:
    • reverse

      public static long[] reverse(long[] self, 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:
      self - a long array
      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
    • reverse

      public static float[] reverse(float[] self)
      Creates a new float array containing items which are the same as this array but in reverse order.
       float[] array = [1f, 2f]
       assert array.reverse() == [2f, 1f]
       
      Parameters:
      self - a float array
      Returns:
      an array containing the reversed items
      Since:
      5.0.0
      See Also:
    • reverse

      public static float[] reverse(float[] self, 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.
       float[] array = 1f..3f
       def yarra = array.reverse(true)
       assert array == 3f..1f
       assert yarra == 3f..1f
       assert array === yarra
       yarra = array.reverse(false)
       assert array !== yarra
       assert array == 3f..1f
       assert yarra == 1f..3f
       
      Parameters:
      self - a float array
      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
    • reverse

      public static double[] reverse(double[] self)
      Creates a new double array containing items which are the same as this array but in reverse order.
       double[] array = [1d, 2d]
       assert array.reverse() == [2d, 1d]
       
      Parameters:
      self - a double array
      Returns:
      an array containing the reversed items
      Since:
      5.0.0
      See Also:
    • reverse

      public static double[] reverse(double[] self, 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.
       double[] array = 1d..3d
       def yarra = array.reverse(true)
       assert array == 3d..1d
       assert yarra == 3d..1d
       assert array === yarra
       yarra = array.reverse(false)
       assert array !== yarra
       assert array == 3d..1d
       assert yarra == 1d..3d
       
      Parameters:
      self - a double array
      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
    • reverse

      public static <T> T[] reverse(T[] self)
      Creates a new array containing items which are the same as this array but in reverse order.
      Parameters:
      self - an array
      Returns:
      An array containing the reversed items.
      Since:
      1.5.5
      See Also:
    • reverse

      public static <T> T[] reverse(T[] self, 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.
       def array = new Object[] {1,2,3}
       def yarra = array.reverse(true)
       assert array == 3..1
       assert yarra == 3..1
      
       yarra = array.reverse(false)
       assert array == 3..1
       assert yarra == 1..3
       
      Parameters:
      self - an array
      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:
      1.8.1
    • reverseEach

      public static boolean[] reverseEach(boolean[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates through a boolean[] in reverse order passing each boolean to the given closure.
       boolean[] array = [false, true, true]
       String result = ''
       array.reverseEach{ result += it }
       assert result == 'truetruefalse'
       
      Parameters:
      self - the boolean array over which we iterate
      closure - the closure applied on each boolean
      Returns:
      the self array
      Since:
      5.0.0
    • reverseEach

      public static byte[] reverseEach(byte[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates through a byte[] in reverse order passing each byte to the given closure.
       byte[] array = [0, 1, 2]
       String result = ''
       array.reverseEach{ result += it }
       assert result == '210'
       
      Parameters:
      self - the byte array over which we iterate
      closure - the closure applied on each byte
      Returns:
      the self array
      Since:
      5.0.0
    • reverseEach

      public static char[] reverseEach(char[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates through a char[] in reverse order passing each char to the given closure.
       char[] array = 'abc'.chars
       String result = ''
       array.reverseEach{ result += it }
       assert result == 'cba'
       
      Parameters:
      self - the char array over which we iterate
      closure - the closure applied on each char
      Returns:
      the self array
      Since:
      5.0.0
    • reverseEach

      public static short[] reverseEach(short[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates through a short[] in reverse order passing each short to the given closure.
       short[] array = [0, 1, 2]
       String result = ''
       array.reverseEach{ result += it }
       assert result == '210'
       
      Parameters:
      self - the short array over which we iterate
      closure - the closure applied on each short
      Returns:
      the self array
      Since:
      5.0.0
    • reverseEach

      public static int[] reverseEach(int[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates 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'
       
      Parameters:
      self - the int array over which we iterate
      closure - the closure applied on each int
      Returns:
      the self array
      Since:
      5.0.0
    • reverseEach

      public static long[] reverseEach(long[] self, @ClosureParams(Component.class) 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:
      self - the long array over which we iterate
      closure - the closure applied on each long
      Returns:
      the self array
      Since:
      5.0.0
    • reverseEach

      public static float[] reverseEach(float[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates through a float[] in reverse order passing each float to the given closure.
       float[] array = [0, 1, 2]
       String result = ''
       array.reverseEach{ result += it }
       assert result == '2.01.00.0'
       
      Parameters:
      self - the float array over which we iterate
      closure - the closure applied on each float
      Returns:
      the self array
      Since:
      5.0.0
    • reverseEach

      public static double[] reverseEach(double[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates through a double[] in reverse order passing each double to the given closure.
       double[] array = [0, 1, 2]
       String result = ''
       array.reverseEach{ result += it }
       assert result == '2.01.00.0'
       
      Parameters:
      self - the double array over which we iterate
      closure - the closure applied on each double
      Returns:
      the self array
      Since:
      5.0.0
    • reverseEach

      public static <T> T[] reverseEach(T[] self, @ClosureParams(Component.class) Closure<?> closure)
      Iterates over each element of the array in the reverse order.
      Parameters:
      self - an array
      closure - a closure to which each item is passed
      Returns:
      the original array
      Since:
      1.5.2
    • shuffle

      public static <T> void shuffle(T[] self)
      Randomly reorders the elements of the specified array.
       Integer[] array = [10, 5, 20]
       def origSize = array.size()
       def items = array.toList()
       array.shuffle()
       assert array.size() == origSize
       assert items.every{ array.contains(it) }
       
      Parameters:
      self - an array
      Since:
      3.0.0
    • shuffle

      public static <T> void shuffle(T[] self, Random rnd)
      Randomly reorders the elements of the specified array using the specified random instance as the source of randomness.
       def r = new Random()
       Integer[] array = [10, 5, 20]
       def origSize = array.size()
       def items = array.toList()
       array.shuffle(r)
       assert array.size() == origSize
       assert items.every{ array.contains(it) }
       
      Parameters:
      self - an array
      Since:
      3.0.0
    • shuffled

      public static <T> T[] shuffled(T[] self)
      Creates a new array containing the elements of the specified array but in a random order.
       Integer[] orig = [10, 5, 20]
       def array = orig.shuffled()
       assert orig.size() == array.size()
       assert orig.every{ array.contains(it) }
       
      Parameters:
      self - an array
      Returns:
      the shuffled array
      Since:
      3.0.0
    • shuffled

      public static <T> T[] shuffled(T[] self, Random rnd)
      Creates a new array containing the elements of the specified array but in a random order using the specified random instance as the source of randomness.
       def r = new Random()
       Integer[] orig = [10, 5, 20]
       def array = orig.shuffled(r)
       assert orig.size() == array.size()
       assert orig.every{ array.contains(it) }
       
      Parameters:
      self - an array
      Returns:
      the shuffled array
      Since:
      3.0.0
    • size

      public static int size(boolean[] self)
      Provides arrays with a size method similar to collections.
       boolean[] array = [true, false, true]
       assert array.size() == 3
       
      Parameters:
      self - a boolean array
      Returns:
      the length of the array
      Since:
      1.5.0
    • size

      public static int size(byte[] self)
      Provides arrays with a size method similar to collections.
      Parameters:
      self - a byte array
      Returns:
      the length of the array
      Since:
      1.0
    • size

      public static int size(char[] self)
      Provides arrays with a size method similar to collections.
      Parameters:
      self - a char array
      Returns:
      the length of the array
      Since:
      1.0
    • size

      public static int size(short[] self)
      Provides arrays with a size method similar to collections.
      Parameters:
      self - a short array
      Returns:
      the length of the array
      Since:
      1.0
    • size

      public static int size(int[] self)
      Provides arrays with a size method similar to collections.
      Parameters:
      self - an int array
      Returns:
      the length of the array
      Since:
      1.0
    • size

      public static int size(long[] self)
      Provides arrays with a size method similar to collections.
      Parameters:
      self - a long array
      Returns:
      the length of the array
      Since:
      1.0
    • size

      public static int size(float[] self)
      Provides arrays with a size method similar to collections.
      Parameters:
      self - a float array
      Returns:
      the length of the array
      Since:
      1.0
    • size

      public static int size(double[] self)
      Provides arrays with a size method similar to collections.
      Parameters:
      self - a double array
      Returns:
      the length of the array
      Since:
      1.0
    • size

      public static int size(Object[] self)
      Provides the standard Groovy size() method for an array.
      Parameters:
      self - an object array
      Returns:
      the length of the array
      Since:
      1.0
    • sort

      public static <T> T[] sort(T[] self)
      Modifies this array so that its elements are in sorted order. The array items are assumed to be comparable.
      Parameters:
      self - the array to be sorted
      Returns:
      the sorted array
      Since:
      1.5.5
    • sort

      public static <T> T[] sort(T[] self, boolean mutate)
      Sorts the given array into sorted order. The array items are assumed to be comparable. If mutate is true, the array is sorted in place and returned. Otherwise, a new sorted array is returned and the original array remains unchanged.
       def orig = ["hello","hi","Hey"] as String[]
       def sorted = orig.sort(false)
       assert orig == ["hello","hi","Hey"] as String[]
       assert sorted == ["Hey","hello","hi"] as String[]
       orig.sort(true)
       assert orig == ["Hey","hello","hi"] as String[]
       
      Parameters:
      self - the array to be sorted
      mutate - false will always cause a new array to be created, true will mutate the array in place
      Returns:
      the sorted array
      Since:
      1.8.1
    • sort

      public static <T> T[] sort(T[] self, Comparator<? super T> comparator)
      Sorts the given array into sorted order using the given comparator.
      Parameters:
      self - the array to be sorted
      comparator - a Comparator used for the comparison
      Returns:
      the sorted array
      Since:
      1.5.5
    • sort

      public static <T> T[] sort(T[] self, boolean mutate, Comparator<? super T> comparator)
      Modifies this array so that its elements are in sorted order as determined by the given comparator. If mutate is true, the array is sorted in place and returned. Otherwise, a new sorted array is returned and the original array remains unchanged.
       def orig = ["hello","hi","Hey"] as String[]
       def sorted = orig.sort(false, String.CASE_INSENSITIVE_ORDER)
       assert orig == ["hello","hi","Hey"] as String[]
       assert sorted == ["hello","Hey","hi"] as String[]
       orig.sort(true, String.CASE_INSENSITIVE_ORDER)
       assert orig == ["hello","Hey","hi"] as String[]
       
      Parameters:
      self - the array containing elements to be sorted
      mutate - false will always cause a new array to be created, true will mutate arrays in place
      comparator - a Comparator used for the comparison
      Returns:
      a sorted array
      Since:
      1.8.1
    • sort

      public static <T> T[] sort(T[] self, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure)
      Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.

      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:
      self - the array containing the elements to be sorted
      closure - a Closure used to determine the correct ordering
      Returns:
      the sorted array
      Since:
      1.5.5
    • sort

      public static <T> T[] sort(T[] self, boolean mutate, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure)
      Modifies this array so that its elements are in sorted order using the Closure to determine the correct ordering. If mutate is false, a new array is returned and the original array remains unchanged. Otherwise, the original array is sorted in place and returned.

      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.

       def orig = ["hello","hi","Hey"] as String[]
       def sorted = orig.sort(false) { it.size() }
       assert orig == ["hello","hi","Hey"] as String[]
       assert sorted == ["hi","Hey","hello"] as String[]
       orig.sort(true) { it.size() }
       assert orig == ["hi","Hey","hello"] as String[]
       
      Parameters:
      self - the array to be sorted
      mutate - false will always cause a new array to be created, true will mutate arrays in place
      closure - a Closure used to determine the correct ordering
      Returns:
      the sorted array
      Since:
      1.8.1
    • split

      public static <T> Collection<Collection<T>> split(T[] self, @ClosureParams(Component.class) 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.
      Parameters:
      self - an Array
      closure - a closure condition
      Returns:
      a List whose first item is the accepted values and whose second item is the rejected values
      Since:
      2.5.0
    • sum

      public static byte sum(byte[] self)
      Sums the items in an array.
      assert (1+2+3+4 as byte) == ([1,2,3,4] as byte[]).sum()
      Parameters:
      self - The array of values to add together
      Returns:
      The sum of all the items
      Since:
      2.4.2
    • sum

      public static char sum(char[] self)
      Sums the items in an array.
      assert (1+2+3+4 as char) == ([1,2,3,4] as char[]).sum()
      Parameters:
      self - The array of values to add together
      Returns:
      The sum of all the items
      Since:
      2.4.2
    • sum

      public static short sum(short[] self)
      Sums the items in an array.
      assert (1+2+3+4 as short) == ([1,2,3,4] as short[]).sum()
      Parameters:
      self - The array of values to add together
      Returns:
      The sum of all the items
      Since:
      2.4.2
    • sum

      public static int sum(int[] self)
      Sums the items in an array.
      assert 1+2+3+4 == ([1,2,3,4] as int[]).sum()
      Parameters:
      self - The array of values to add together
      Returns:
      The sum of all the items
      Since:
      2.4.2
    • sum

      public static long sum(long[] self)
      Sums the items in an array.
      assert (1+2+3+4 as long) == ([1,2,3,4] as long[]).sum()
      Parameters:
      self - The array of values to add together
      Returns:
      The sum of all the items
      Since:
      2.4.2
    • sum

      public static float sum(float[] self)
      Sums the items in an array.
      assert (1+2+3+4 as float) == ([1,2,3,4] as float[]).sum()
      Parameters:
      self - The array of values to add together
      Returns:
      The sum of all the items
      Since:
      2.4.2
    • sum

      public static double sum(double[] self)
      Sums the items in an array.
      assert (1+2+3+4 as double) == ([1,2,3,4] as double[]).sum()
      Parameters:
      self - The array of values to add together
      Returns:
      The sum of all the items
      Since:
      2.4.2
    • sum

      public static Object sum(Object[] self)
      Sums the items in an array. This is equivalent to invoking the "plus" method on all items in the array.
      Parameters:
      self - The array of values to add together
      Returns:
      The sum of all the items
      Since:
      1.7.1
      See Also:
    • sum

      public static byte sum(byte[] self, byte initialValue)
      Sums the items in an array, adding the result to some initial value.
      assert (5+1+2+3+4 as byte) == ([1,2,3,4] as byte[]).sum(5 as byte)
      Parameters:
      self - an array of values to sum
      initialValue - the items in the array will be summed to this initial value
      Returns:
      The sum of all the items.
      Since:
      2.4.2
    • sum

      public static char sum(char[] self, char initialValue)
      Sums the items in an array, adding the result to some initial value.
      assert (5+1+2+3+4 as char) == ([1,2,3,4] as char[]).sum(5 as char)
      Parameters:
      self - an array of values to sum
      initialValue - the items in the array will be summed to this initial value
      Returns:
      The sum of all the items.
      Since:
      2.4.2
    • sum

      public static short sum(short[] self, short initialValue)
      Sums the items in an array, adding the result to some initial value.
      assert (5+1+2+3+4 as short) == ([1,2,3,4] as short[]).sum(5 as short)
      Parameters:
      self - an array of values to sum
      initialValue - the items in the array will be summed to this initial value
      Returns:
      The sum of all the items.
      Since:
      2.4.2
    • sum

      public static int sum(int[] self, int initialValue)
      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)
      Parameters:
      self - an array of values to sum
      initialValue - the items in the array will be summed to this initial value
      Returns:
      The sum of all the items.
      Since:
      2.4.2
    • sum

      public static long sum(long[] self, 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:
      self - an array of values to sum
      initialValue - the items in the array will be summed to this initial value
      Returns:
      The sum of all the items.
      Since:
      2.4.2
    • sum

      public static float sum(float[] self, float initialValue)
      Sums the items in an array, adding the result to some initial value.
      assert (5+1+2+3+4 as float) == ([1,2,3,4] as float[]).sum(5)
      Parameters:
      self - an array of values to sum
      initialValue - the items in the array will be summed to this initial value
      Returns:
      The sum of all the items.
      Since:
      2.4.2
    • sum

      public static double sum(double[] self, double initialValue)
      Sums the items in an array, adding the result to some initial value.
      assert (5+1+2+3+4 as double) == ([1,2,3,4] as double[]).sum(5)
      Parameters:
      self - an array of values to sum
      initialValue - the items in the array will be summed to this initial value
      Returns:
      The sum of all the items.
      Since:
      2.4.2
    • sum

      public static Object sum(Object[] self, Object initialValue)
      Sums the items in an array, adding the result to some initial value.
      Parameters:
      self - an array of values to sum
      initialValue - the items in the array will be summed to this initial value
      Returns:
      The sum of all the items.
      Since:
      1.7.1
    • sum

      public static <T> Object sum(T[] self, @ClosureParams(Component.class) Closure<?> closure)
      Sums the result of applying a closure to each item of an array. array.sum(closure) is equivalent to: array.collect(closure).sum().
      Parameters:
      self - An array
      closure - a single parameter closure that returns a (typically) numeric value.
      Returns:
      The sum of the values returned by applying the closure to each item of the array.
      Since:
      1.7.1
    • sum

      public static <T> Object sum(T[] self, Object initialValue, @ClosureParams(Component.class) Closure<?> closure)
      Sums the result of applying a closure to each item of an array to some initial value. array.sum(initVal, closure) is equivalent to: array.collect(closure).sum(initVal).
      Parameters:
      self - an array
      closure - a single parameter closure that returns a (typically) numeric value.
      initialValue - the closure results will be summed to this initial value
      Returns:
      The sum of the values returned by applying the closure to each item of the array.
      Since:
      1.7.1
    • swap

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

      Example:

       assert ([false, true, false, true] as boolean[]) == ([false, false, true, true] as boolean[]).swap(1, 2)
       
      Parameters:
      self - a boolean array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • swap

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

      Example:

       assert ([1, 3, 2, 4] as byte[]) == ([1, 2, 3, 4] as byte[]).swap(1, 2)
       
      Parameters:
      self - a boolean array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • swap

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

      Example:

       assert ([1, 3, 2, 4] as char[]) == ([1, 2, 3, 4] as char[]).swap(1, 2)
       
      Parameters:
      self - a boolean array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • swap

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

      Example:

       assert ([1, 3, 2, 4] as short[]) == ([1, 2, 3, 4] as short[]).swap(1, 2)
       
      Parameters:
      self - a boolean array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • swap

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

      Example:

       assert ([1, 3, 2, 4] as int[]) == ([1, 2, 3, 4] as int[]).swap(1, 2)
       
      Parameters:
      self - a boolean array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • swap

      public static long[] swap(long[] self, 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:
      self - a boolean array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • swap

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

      Example:

       assert ([1, 3, 2, 4] as float[]) == ([1, 2, 3, 4] as float[]).swap(1, 2)
       
      Parameters:
      self - a boolean array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • swap

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

      Example:

       assert ([1, 3, 2, 4] as double[]) == ([1, 2, 3, 4] as double[]).swap(1, 2)
       
      Parameters:
      self - a boolean array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • swap

      public static <T> T[] swap(T[] self, int i, int j)
      Swaps two elements at the specified positions.

      Example:

       assert (["a", "c", "b", "d"] as String[]) == (["a", "b", "c", "d"] as String[]).swap(1, 2)
       
      Parameters:
      self - an array
      i - a position
      j - a position
      Returns:
      self
      Since:
      2.4.0
    • tail

      public static boolean[] tail(boolean[] self)
      Returns the items from the boolean array excluding the first item.
       boolean[] array = [true, false, true]
       def result = array.tail()
       assert result == [false, true]
       assert array.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • tail

      public static byte[] tail(byte[] self)
      Returns the items from the byte array excluding the first item.
       byte[] bytes = [1, 2, 3]
       def result = bytes.tail()
       assert result == [2, 3]
       assert bytes.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • tail

      public static char[] tail(char[] self)
      Returns the items from the char array excluding the first item.
       char[] chars = ['a', 'b', 'c']
       def result = chars.tail()
       assert result == ['b', 'c']
       assert chars.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • tail

      public static short[] tail(short[] self)
      Returns the items from the short array excluding the first item.
       short[] shorts = [10, 20, 30]
       def result = shorts.tail()
       assert result == [20, 30]
       assert shorts.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • tail

      public static int[] tail(int[] self)
      Returns 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
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • tail

      public static long[] tail(long[] self)
      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
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • tail

      public static float[] tail(float[] self)
      Returns the items from the float array excluding the first item.
       float[] floats = [2.0f, 4.0f, 6.0f]
       def result = floats.tail()
       assert result == [4.0f, 6.0f]
       assert floats.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • tail

      public static double[] tail(double[] self)
      Returns the items from the double array excluding the first item.
       double[] doubles = [10.0d, 20.0d, 30.0d]
       def result = doubles.tail()
       assert result == [20.0d, 30.0d]
       assert doubles.class.componentType == result.class.componentType
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      5.0.0
    • tail

      public static <T> T[] tail(T[] self)
      Returns the items from the array excluding the first item.
       String[] strings = ["a", "b", "c"]
       def result = strings.tail()
       assert result.class.componentType == String
       String[] expected = ["b", "c"]
       assert result == expected
       
      Parameters:
      self - an array
      Returns:
      an array without its first element
      Throws:
      UnsupportedOperationException - if the array is empty
      Since:
      1.7.3
    • take

      public static <T> T[] take(T[] self, int num)
      Returns the first num elements from the head of this array.
       String[] strings = [ 'a', 'b', 'c' ]
       assert strings.take( 0 ) == [] as String[]
       assert strings.take( 2 ) == [ 'a', 'b' ] as String[]
       assert strings.take( 5 ) == [ 'a', 'b', 'c' ] as String[]
       
      Parameters:
      self - the original array
      num - the number of elements to take from this array
      Returns:
      an array consisting of the first num elements of this array, or else the whole array if it has less than num elements.
      Since:
      1.8.1
    • takeRight

      public static <T> T[] takeRight(T[] self, int num)
      Returns the last num elements from the tail of this array.
       String[] strings = [ 'a', 'b', 'c' ]
       assert strings.takeRight( 0 ) == [] as String[]
       assert strings.takeRight( 2 ) == [ 'b', 'c' ] as String[]
       assert strings.takeRight( 5 ) == [ 'a', 'b', 'c' ] as String[]
       
      Parameters:
      self - the original array
      num - the number of elements to take from this array
      Returns:
      an array consisting of the last num elements of this array, or else the whole array if it has less than num elements.
      Since:
      2.4.0
    • takeWhile

      public static <T> T[] takeWhile(T[] self, @ClosureParams(Component.class) Closure<?> condition)
      Returns the longest prefix of this array where each element passed to the given closure evaluates to true.
       def nums = [ 1, 3, 2 ] as Integer[]
       assert nums.takeWhile{ it < 1 } == [] as Integer[]
       assert nums.takeWhile{ it < 3 } == [ 1 ] as Integer[]
       assert nums.takeWhile{ it < 4 } == [ 1, 3, 2 ] as Integer[]
       
      Parameters:
      self - the original array
      condition - the closure that must evaluate to true to continue taking elements
      Returns:
      A prefix of the given array where each element passed to the given closure evaluates to true.
      Since:
      1.8.7
    • toList

      public static List<Boolean> toList(boolean[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - a boolean array
      Returns:
      A list containing the contents of this array.
      Since:
      1.6.0
    • toList

      public static List<Byte> toList(byte[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - a byte array
      Returns:
      A list containing the contents of this array.
      Since:
      1.0
    • toList

      public static List<Character> toList(char[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - a char array
      Returns:
      A list containing the contents of this array.
      Since:
      1.0
    • toList

      public static List<Short> toList(short[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - a short array
      Returns:
      A list containing the contents of this array.
      Since:
      1.0
    • toList

      public static List<Integer> toList(int[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - an int array
      Returns:
      A list containing the contents of this array.
      Since:
      1.0
    • toList

      public static List<Long> toList(long[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - a long array
      Returns:
      A list containing the contents of this array.
      Since:
      1.0
    • toList

      public static List<Float> toList(float[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - a float array
      Returns:
      A list containing the contents of this array.
      Since:
      1.0
    • toList

      public static List<Double> toList(double[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - a double array
      Returns:
      A list containing the contents of this array.
      Since:
      1.0
    • toList

      public static <T> List<T> toList(T[] self)
      Converts this array to a List of the same size, with each element added to the list.
      Parameters:
      self - an object array
      Returns:
      A mutable list containing the contents of this array.
      Since:
      1.0
    • toSet

      public static Set<Boolean> toSet(boolean[] self)
      Converts this array to a Set, with each unique element added to the set.
       boolean[] array = [true, false, true]
       Set expected = [true, false]
       assert array.toSet() == expected
       
      Parameters:
      self - a boolean array
      Returns:
      A set containing the unique contents of this array.
      Since:
      1.8.0
    • toSet

      public static Set<Byte> toSet(byte[] self)
      Converts this array to a Set, with each unique element added to the set.
       byte[] array = [1, 2, 3, 2, 1]
       Set expected = [1, 2, 3]
       assert array.toSet() == expected
       
      Parameters:
      self - a byte array
      Returns:
      A set containing the unique contents of this array.
      Since:
      1.8.0
    • toSet

      public static Set<Character> toSet(char[] self)
      Converts this array to a Set, with each unique element added to the set.
       char[] array = 'xyzzy'.chars
       Set expected = ['x', 'y', 'z']
       assert array.toSet() == expected
       
      Parameters:
      self - a char array
      Returns:
      A set containing the unique contents of this array.
      Since:
      1.8.0
    • toSet

      public static Set<Short> toSet(short[] self)
      Converts this array to a Set, with each unique element added to the set.
       short[] array = [1, 2, 3, 2, 1]
       Set expected = [1, 2, 3]
       assert array.toSet() == expected
       
      Parameters:
      self - a short array
      Returns:
      A set containing the unique contents of this array.
      Since:
      1.8.0
    • toSet

      public static Set<Integer> toSet(int[] self)
      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
       
      Parameters:
      self - an int array
      Returns:
      A set containing the unique contents of this array.
      Since:
      1.8.0
    • toSet

      public static Set<Long> toSet(long[] self)
      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
       
      Parameters:
      self - a long array
      Returns:
      A set containing the unique contents of this array.
      Since:
      1.8.0
    • toSet

      public static Set<Float> toSet(float[] self)
      Converts this array to a Set, with each unique element added to the set.
       float[] array = [1.0f, 2.0f, 3.0f, 2.0f, 1.0f]
       Set expected = [1.0f, 2.0f, 3.0f]
       assert array.toSet() == expected
       
      Parameters:
      self - a float array
      Returns:
      A set containing the unique contents of this array.
      Since:
      1.8.0
    • toSet

      public static Set<Double> toSet(double[] self)
      Converts this array to a Set, with each unique element added to the set.
       double[] array = [1.0d, 2.0d, 3.0d, 2.0d, 1.0d]
       Set expected = [1.0d, 2.0d, 3.0d]
       assert array.toSet() == expected
       
      Parameters:
      self - a double array
      Returns:
      A set containing the unique contents of this array.
      Since:
      1.8.0
    • toSet

      public static <T> Set<T> toSet(T[] self)
      Converts this array to a Set, with each unique element added to the set.
      Parameters:
      self - an object array
      Returns:
      A set containing the unique contents of this array.
      Since:
      5.0.0
    • toSorted

      public static <T> T[] toSorted(T[] self)
      Returns a sorted version of the given array using the supplied comparator.
      Parameters:
      self - the array to be sorted
      Returns:
      the sorted array
      Since:
      2.4.0
      See Also:
    • toSorted

      public static <T> T[] toSorted(T[] self, Comparator<? super T> comparator)
      Returns a sorted version of the given array using the supplied comparator to determine the resulting order.
       def sumDigitsComparator = [compare: { num1, num2 -> num1.toString().toList()*.toInteger().sum() <=> num2.toString().toList()*.toInteger().sum() }] as Comparator
       Integer[] nums = [9, 44, 222, 7000]
       def result = nums.toSorted(sumDigitsComparator)
       assert result instanceof Integer[]
       assert result == [222, 7000, 44, 9]
       
      Parameters:
      self - the array to be sorted
      comparator - a Comparator used for the comparison
      Returns:
      the sorted array
      Since:
      2.4.0
    • toSorted

      public static <T> T[] toSorted(T[] self, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure)
      Sorts the elements from this array into a newly created array using the Closure to determine the correct ordering.

      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:
      self - the array containing the elements to be sorted
      closure - a Closure used to determine the correct ordering
      Returns:
      a sorted array
      Since:
      2.4.0
      See Also:
    • toSpreadMap

      public static SpreadMap toSpreadMap(Object[] self)
      Creates a spreadable map from this array.

      Parameters:
      self - an object array
      Returns:
      a newly created SpreadMap
      Since:
      1.0
      See Also:
    • toString

      public static String toString(boolean[] self)
      Returns the string representation of the given array.
       boolean[] array = [false, true, false]
       assert array.toString() == '[false, true, false]'
       
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.6.0
    • toString

      public static String toString(byte[] self)
      Returns the string representation of the given array.
       byte[] array = [1, 2, 3, 2, 1]
       assert array.toString() == '[1, 2, 3, 2, 1]'
       
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.6.0
    • toString

      public static String toString(char[] self)
      Returns the string representation of the given array.
       char[] array = 'abcd'.chars
       assert array instanceof char[]
       assert array.toString() == 'abcd'
       
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.6.0
    • toString

      public static String toString(short[] self)
      Returns the string representation of the given array.
       short[] array = [1, 2, 3, 2, 1]
       assert array.toString() == '[1, 2, 3, 2, 1]'
       
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.6.0
    • toString

      public static String toString(int[] self)
      Returns the string representation of the given array.
       int[] array = [1, 2, 3, 2, 1]
       assert array.toString() == '[1, 2, 3, 2, 1]'
       
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.6.0
    • toString

      public static String toString(long[] self)
      Returns the string representation of the given array.
       long[] array = [1, 2, 3, 2, 1]
       assert array.toString() == '[1, 2, 3, 2, 1]'
       
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.6.0
    • toString

      public static String toString(float[] self)
      Returns the string representation of the given array.
       float[] array = [1, 2, 3, 2, 1]
       assert array.toString() == '[1.0, 2.0, 3.0, 2.0, 1.0]'
       
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.6.0
    • toString

      public static String toString(double[] self)
      Returns the string representation of the given array.
       double[] array = [1, 2, 3, 2, 1]
       assert array.toString() == '[1.0, 2.0, 3.0, 2.0, 1.0]'
       
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.6.0
    • toString

      public static String toString(Object[] self)
      Returns the string representation of the given array.
      Parameters:
      self - an array
      Returns:
      the string representation
      Since:
      1.0
    • toUnique

      public static <T> T[] toUnique(T[] self)
      Returns a new Array containing the items from the original Array but with duplicates removed using the natural ordering of the items in the array.

       String[] letters = ['c', 'a', 't', 's', 'a', 't', 'h', 'a', 't']
       String[] expected = ['c', 'a', 't', 's', 'h']
       def result = letters.toUnique()
       assert result == expected
       assert result.class.componentType == String
       
      Parameters:
      self - an array
      Returns:
      the unique items from the array
    • toUnique

      public static <T> T[] toUnique(T[] self, Comparator<? super T> comparator)
      Returns a new Array containing the items from the original Array but with duplicates removed with the supplied comparator determining which items are unique.

       String[] letters = ['c', 'a', 't', 's', 'A', 't', 'h', 'a', 'T']
       String[] lower = ['c', 'a', 't', 's', 'h']
       class LowerComparator implements Comparator {
           int compare(a, b) { a.toLowerCase() <=> b.toLowerCase() }
       }
       assert letters.toUnique(new LowerComparator()) == lower
       
      Parameters:
      self - an array
      comparator - a Comparator used to determine unique (equal) items If null, the Comparable natural ordering of the elements will be used.
      Returns:
      the unique items from the array
    • toUnique

      public static <T> T[] toUnique(T[] self, @ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure)
      Returns a new Array containing the items from the original Array but with duplicates removed with the supplied closure determining which items are unique.

       String[] letters = ['c', 'a', 't', 's', 'A', 't', 'h', 'a', 'T']
       String[] expected = ['c', 'a', 't', 's', 'h']
       assert letters.toUnique{ p1, p2 -> p1.toLowerCase() <=> p2.toLowerCase() } == expected
       assert letters.toUnique{ it.toLowerCase() } == expected
       
      Parameters:
      self - an array
      closure - a Closure used to determine unique items
      Returns:
      the unique items from the array
    • transpose

      public static boolean[][] transpose(boolean[][] self)
      A transpose method for 2D boolean arrays.

      Example usage:

       boolean[][] array = [[false, false], [true, true]]
       boolean[][] expected = [[false, true], [false, true]]
       def result = array.transpose()
       assert result == expected
       assert array.class.componentType == result.class.componentType
       
      Parameters:
      self - a 2D boolean array
      Returns:
      the transposed 2D boolean array
      Since:
      5.0.0
    • transpose

      public static byte[][] transpose(byte[][] self)
      A transpose method for 2D byte arrays.

      Example usage:

       byte[][] bytes = [[1, 10], [2, 20]]
       byte[][] expected = [[1, 2], [10, 20]]
       def result = bytes.transpose()
       assert result == expected
       assert bytes.class.componentType == result.class.componentType
       
      Parameters:
      self - a 2D byte array
      Returns:
      the transposed 2D byte array
      Since:
      5.0.0
    • transpose

      public static char[][] transpose(char[][] self)
      A transpose method for 2D char arrays.

      Example usage:

       char[][] chars = [['a', 'b'], ['A', 'B']]
       char[][] expected = [['a', 'A'], ['b', 'B']]
       def result = chars.transpose()
       assert result == expected
       assert chars.class.componentType == result.class.componentType
       
      Parameters:
      self - a 2D char array
      Returns:
      the transposed 2D char array
      Since:
      5.0.0
    • transpose

      public static short[][] transpose(short[][] self)
      A transpose method for 2D short arrays.

      Example usage:

       short[][] shorts = [[1, 10], [100, 1000]]
       short[][] expected = [[1, 100], [10, 1000]]
       def result = shorts.transpose()
       assert result == expected
       assert shorts.class.componentType == result.class.componentType
       
      Parameters:
      self - a 2D short array
      Returns:
      the transposed 2D short array
      Since:
      5.0.0
    • transpose

      public static int[][] transpose(int[][] self)
      A transpose method for 2D int arrays.

      Example usage:

       int[][] nums = [[10, 15, 20], [30, 35, 40]]
       int[][] expected = [[10, 30], [15, 35], [20, 40]]
       assert nums.transpose() == expected
       
      Parameters:
      self - a 2D int array
      Returns:
      the transposed 2D int array
      Since:
      3.0.8
    • transpose

      public static long[][] transpose(long[][] self)
      A transpose method for 2D long arrays.

      Example usage:

       long[][] longs = [[1L, 3L, 5L], [2L, 4L, 6L]]
       long[][] expected = [[1L, 2L], [3L, 4L], [5L, 6L]]
       def result = longs.transpose()
       assert result == expected
       assert longs.class.componentType == result.class.componentType
       
      Parameters:
      self - a 2D long array
      Returns:
      the transposed 2D long array
      Since:
      3.0.8
    • transpose

      public static float[][] transpose(float[][] self)
      A transpose method for 2D float arrays.

      Example usage:

       float[][] floats = [[1.0f, 10.0f], [2.0f, 20.0f]]
       float[][] expected = [[1.0f, 2.0f], [10.0f, 20.0f]]
       def result = floats.transpose()
       assert result == expected
       assert floats.class.componentType == result.class.componentType
       
      Parameters:
      self - a 2D float array
      Returns:
      the transposed 2D float array
      Since:
      5.0.0
    • transpose

      public static double[][] transpose(double[][] self)
      A transpose method for 2D double arrays.

      Example usage:

       double[][] doubles = [[1.0d, 10.0d], [2.0d, 20.0d]]
       double[][] expected = [[1.0d, 2.0d], [10.0d, 20.0d]]
       def result = doubles.transpose()
       assert result == expected
       assert doubles.class.componentType == result.class.componentType
       
      Parameters:
      self - a 2D double array
      Returns:
      the transposed 2D double array
      Since:
      3.0.8
    • union

      public static Object[] union(Object[] left, Collection<?> right)
      Creates an object array containing elements from an original array plus those from a Collection. This is similar to plus(Object[], Collection) but always return an Object array and so might be more applicable when adding heterogeneous arrays.
       Integer[] a = [1, 2, 3]
       def result = a.union(['foo', 'bar'])
       assert result.class == Object[]
       assert result == new Object[]{1, 2, 3, 'foo', 'bar'}
       
      Parameters:
      left - the array
      right - a Collection to be appended
      Returns:
      A new Object array containing left with right appended to it.
      Since:
      4.0.0
    • union

      public static Object[] union(Object[] left, Iterable<?> right)
      Creates an Object array containing elements from an original array plus those from an Iterable. This is similar to plus(Object[], Iterable) but always return an Object array and so might be more applicable when adding heterogeneous arrays.
       class AbcIterable implements Iterable {
           Iterator iterator() { "abc".iterator() }
       }
       String[] array = ['x', 'y', 'z']
       def result = array.union(new AbcIterable())
       assert result.class == Object[]
       assert result == new Object[]{'x', 'y', 'z', 'a', 'b', 'c'}
       
      Parameters:
      left - the array
      right - an Iterable to be appended
      Returns:
      A new Object array containing elements from left with those from right appended.
      Since:
      4.0.0
    • union

      public static Object[] union(Object[] left, Object[] right)
      Creates an Object array as a union of two arrays. This is similar to plus(Object[], Object[]) but always return an Object array and so might be more applicable when adding heterogeneous arrays.
       Integer[] a = [1, 2, 3]
       String[] b = ['foo', 'bar']
       def result = a.union(b)
       assert result.class == Object[]
       assert result == new Object[]{1, 2, 3, 'foo', 'bar'}
       
      Parameters:
      left - the left Array
      right - the right Array
      Returns:
      A new Object array containing right appended to left.
      Since:
      4.0.0
    • union

      public static Object[] union(Object[] left, Object right)
      Creates an Object array containing elements from an original array plus an additional appended element. This is similar to plus(Object[], Object) but always return an Object array and so might be more applicable when adding heterogeneous arrays.
       Integer[] a = [1, 2, 3]
       def result = a.union('foo')
       assert result.class == Object[]
       assert result == new Object[]{1, 2, 3, 'foo'}
       
      Parameters:
      left - the array
      right - the value to append
      Returns:
      A new Object array containing left with right appended to it.
      Since:
      4.0.0
    • withCollectedKeys

      public static <K, V> Map<K,V> withCollectedKeys(V[] values, Function<? super V,K> keyTransform)
      A variant of withCollectedKeys for arrays.
      Parameters:
      values - an array
      keyTransform - a function for transforming array elements into values
      Returns:
      the collector with all transformed values added to it
      Since:
      5.0.0
      See Also:
    • withCollectedKeys

      public static <K, V> Map<K,V> withCollectedKeys(V[] values, Map<K,V> collector, Function<? super V,K> keyTransform)
      A variant of withCollectedKeys for arrays.
      Parameters:
      values - an array
      collector - the Map into which the transformed entries are put
      keyTransform - a function for transforming array elements into values
      Returns:
      the collector with all transformed values added to it
      Since:
      5.0.0
      See Also:
    • withCollectedValues

      public static <K, V> Map<K,V> withCollectedValues(K[] keys, Function<? super K,V> valueTransform)
      A variant of withCollectedValues for arrays.
      Parameters:
      keys - an array
      valueTransform - a function for transforming array elements into values
      Returns:
      A map of the transformed entries.
      Since:
      5.0.0
    • withCollectedValues

      public static <K, V> Map<K,V> withCollectedValues(K[] keys, Map<K,V> collector, Function<? super K,V> valueTransform)
      A variant of withCollectedValues for arrays.
      Parameters:
      keys - an array
      collector - the Map into which the transformed entries are put
      valueTransform - a function for transforming array elements into values
      Returns:
      The collector with all transformed values added to it.
      Since:
      5.0.0