public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport
Defines new groovy methods which appear on 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 an 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.
Type Params | Return Type | Name and description |
---|---|---|
|
public static boolean |
any(boolean[] self) Iterates over the contents of a boolean Array, and checks whether any element is true. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
<T> |
public static 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. |
|
public static boolean |
asBoolean(boolean[] self) Coerces a boolean array to a boolean value. |
|
public static boolean |
asBoolean(byte[] self) Coerces a byte array to a boolean value. |
|
public static boolean |
asBoolean(char[] self) Coerces a char array to a boolean value. |
|
public static boolean |
asBoolean(short[] self) Coerces a short array to a boolean value. |
|
public static boolean |
asBoolean(int[] self) Coerces an int array to a boolean value. |
|
public static boolean |
asBoolean(long[] self) Coerces a long array to a boolean value. |
|
public static boolean |
asBoolean(float[] self) Coerces a float array to a boolean value. |
|
public static boolean |
asBoolean(double[] self) Coerces a double array to a boolean value. |
|
public static boolean |
asBoolean(Object[] self) Coerces an object array to a boolean value. |
<T> |
public static T |
asType(Object[] self, Class<T> type) Converts the given array to either a List, Set, or SortedSet. |
|
public static BigDecimal |
average(byte[] self) Calculates the average of the bytes in the array. |
|
public static BigDecimal |
average(short[] self) Calculates the average of the shorts in the array. |
|
public static BigDecimal |
average(int[] self) Calculates the average of the ints in the array. |
|
public static BigDecimal |
average(long[] self) Calculates the average of the longs in the array. |
|
public static double |
average(float[] self) Calculates the average of the floats in the array. |
|
public static double |
average(double[] self) Calculates the average of the doubles in the array. |
|
public static Object |
average(Object[] self) Averages the items in an array. |
<T> |
public static Object |
average(T[] self, Closure<?> closure) Averages the result of applying a closure to each item of an array. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
<T> |
public static List<List<T>> |
chop(T[] self, int chopSizes) Chops the array into pieces, returning lists with sizes corresponding to the supplied chop sizes. |
<T> |
public static List<List<T>> |
collate(T[] self, int size) Collates an array. |
<T> |
public static List<List<T>> |
collate(T[] self, int size, int step) Collates an array into sub-lists. |
<T> |
public static List<List<T>> |
collate(T[] self, int size, boolean keepRemainder) Collates this array into sub-lists. |
<T> |
public static List<List<T>> |
collate(T[] self, int size, int step, boolean keepRemainder) Collates this array into sub-lists. |
<E, T> |
public static 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. |
<E, T, C extends Collection<T>> |
public static 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 . |
<K, V, E> |
public static Map<K, V> |
collectEntries(E[] self) A variant of collectEntries using the identity closure as the transform. |
<K, V, E> |
public static Map<K, V> |
collectEntries(E[] self, Map<K, V> collector) A variant of collectEntries using the identity closure as the transform. |
<K, V, E> |
public static 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. |
<K, V, E> |
public static 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. |
<K, V, E> |
public static 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. |
<K, V, E> |
public static 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. |
<T, E> |
public static 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. |
<T, E, C extends Collection<T>> |
public static 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. |
|
public static Iterator<double[]> |
columns(double self) An iterator of the columns of the array. |
|
public static Iterator<float[]> |
columns(float self) An iterator of the columns of the array. |
|
public static Iterator<int[]> |
columns(int self) An iterator of the columns of the array. |
|
public static Iterator<long[]> |
columns(long self) An iterator of the columns of the array. |
|
public static boolean |
contains(boolean[] self, Object value) Checks whether the array contains the given value. |
|
public static boolean |
contains(byte[] self, Object value) Checks whether the array contains the given value. |
|
public static boolean |
contains(char[] self, Object value) Checks whether the array contains the given value. |
|
public static boolean |
contains(short[] self, Object value) Checks whether the array contains the given value. |
|
public static boolean |
contains(int[] self, Object value) Checks whether the array contains the given value. |
|
public static boolean |
contains(long[] self, Object value) Checks whether the array contains the given value. |
|
public static boolean |
contains(float[] self, Object value) Checks whether the array contains the given value. |
|
public static boolean |
contains(double[] self, Object value) Checks whether the array contains the given value. |
|
public static boolean |
contains(Object[] self, Object value) Checks whether the array contains the given value. |
|
public static Number |
count(boolean[] self, Object value) Counts the number of occurrences of the given value inside this array. |
|
public static Number |
count(byte[] self, Object value) Counts the number of occurrences of the given value inside this array. |
|
public static Number |
count(char[] self, Object value) Counts the number of occurrences of the given value inside this array. |
|
public static Number |
count(short[] self, Object value) Counts the number of occurrences of the given value inside this array. |
|
public static Number |
count(int[] self, Object value) Counts the number of occurrences of the given value inside this array. |
|
public static Number |
count(long[] self, Object value) Counts the number of occurrences of the given value inside this array. |
|
public static Number |
count(float[] self, Object value) Counts the number of occurrences of the given value inside this array. |
|
public static Number |
count(double[] self, Object value) Counts the number of occurrences of the given value inside this array. |
|
public static Number |
count(Object[] self, Object value) Counts the number of occurrences of the given value inside this array. |
<T> |
public static Number |
count(T[] self, Closure<?> predicate) Counts the number of occurrences which satisfy the given closure from inside this array. |
<K, E> |
public static 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. |
<E> |
public static Map<E, Integer> |
countBy(E[] self) Creates a multiset-like map of the array members. |
<T> |
public static T[] |
drop(T[] self, int num) Drops the given number of elements from the head of this array if they are available. |
<T> |
public static T[] |
dropRight(T[] self, int num) Drops the given number of elements from the tail of this array if they are available. |
<T> |
public static 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. |
|
public static boolean[] |
each(boolean[] self, Consumer<Boolean> consumer) Iterates through a boolean[] passing each boolean to the given consumer. |
|
public static byte[] |
each(byte[] self, Consumer<Byte> consumer) Iterates through a byte[] passing each byte to the given consumer. |
|
public static char[] |
each(char[] self, Consumer<Character> consumer) Iterates through a char[] passing each char to the given consumer. |
|
public static short[] |
each(short[] self, Consumer<Short> consumer) Iterates through a short[] passing each short to the given consumer. |
|
public static int[] |
each(int[] self, IntConsumer consumer) Iterates through an int[] passing each int to the given consumer. |
|
public static long[] |
each(long[] self, LongConsumer consumer) Iterates through a long[] passing each long to the given consumer. |
|
public static float[] |
each(float[] self, Consumer<Float> consumer) Iterates through a float[] passing each float to the given consumer. |
|
public static double[] |
each(double[] self, DoubleConsumer consumer) Iterates through a double[] passing each double to the given consumer. |
<T> |
public static T[] |
each(T[] self, Closure<?> closure) Iterates through an array passing each array entry to the given closure. |
|
public static void |
eachByte(byte[] self, Closure<?> closure) Traverses through each byte of this byte array. |
|
public static void |
eachByte(Byte[] self, Closure<?> closure) Traverses through each byte of this Byte array. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
<T> |
public static 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. |
|
public static boolean |
equals(boolean[] self, boolean[] right) Compares the contents of this array to the contents of the given array. |
|
public static boolean |
equals(byte[] self, byte[] right) Compares the contents of this array to the contents of the given array. |
|
public static boolean |
equals(char[] self, char[] right) Compares the contents of this array to the contents of the given array. |
|
public static boolean |
equals(short[] self, short[] right) Compares the contents of this array to the contents of the given array. |
|
public static boolean |
equals(int[] self, int[] right) Compares the contents of this array to the contents of the given array. |
|
public static boolean |
equals(long[] self, long[] right) Compares the contents of this array to the contents of the given array. |
|
public static boolean |
equals(float[] self, float[] right) Compares the contents of this array to the contents of the given array. |
|
public static boolean |
equals(double[] self, double[] right) Compares the contents of this array to the contents of the given array. |
|
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. |
|
public static boolean |
every(boolean[] self) Iterates over the contents of a boolean Array, and checks whether every element is true. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
|
public 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. |
<T> |
public static boolean |
every(T[] self, Closure<?> predicate) Used to determine if the given predicate closure is valid (i.e. returns true for all items in this Array). |
<T> |
public static T |
find(T[] self, Closure<?> condition) Finds the first element in the array that matches the given closure condition. |
<T> |
public static List<T> |
findAll(T[] self) Finds the elements of the array matching the IDENTITY Closure (i.e. matching Groovy truth). |
<T> |
public static List<T> |
findAll(T[] self, Closure<?> condition) Finds all elements of the array matching the given Closure condition. |
<T> |
public static 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. |
<T> |
public static 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. |
<T> |
public static 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. |
<T> |
public static 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. |
<T> |
public static int |
findLastIndexOf(T[] self, Closure<?> condition) Returns the index of the last item that matches the specified condition. |
<T> |
public static 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. |
<T> |
public static T |
findResult(T[] self) Iterates through the Array stopping once the first non-null result is found and returning that result. |
<T, U extends T, V extends T> |
public static T |
findResult(U[] self, V defaultResult) Iterates through the Array stopping once the first non-null result is found and returning that result. |
<S, T> |
public static 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. |
<S, T, U extends T, V extends T> |
public static 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. |
<T> |
public static Collection<T> |
findResults(T[] self) Iterates through the Array collecting any non-null results. |
<T, U> |
public static Collection<T> |
findResults(U[] self, Closure<T> filteringTransform) Iterates through the Array transforming items using the supplied closure and collecting any non-null results. |
|
public static boolean |
first(boolean[] self) Returns the first item from the boolean array. |
|
public static byte |
first(byte[] self) Returns the first item from the byte array. |
|
public static char |
first(char[] self) Returns the first item from the char array. |
|
public static short |
first(short[] self) Returns the first item from the short array. |
|
public static int |
first(int[] self) Returns the first item from the int array. |
|
public static long |
first(long[] self) Returns the first item from the long array. |
|
public static float |
first(float[] self) Returns the first item from the float array. |
|
public static double |
first(double[] self) Returns the first item from the double array. |
<T> |
public static T |
first(T[] self) Returns the first item from the array. |
|
public static List<Boolean> |
flatten(boolean[] self) Flattens an array. |
|
public static List<Byte> |
flatten(byte[] self) Flattens an array. |
|
public static List<Character> |
flatten(char[] self) Flattens an array. |
|
public static List<Short> |
flatten(short[] self) Flattens an array. |
|
public static List<Integer> |
flatten(int[] self) Flattens an array. |
|
public static List<Long> |
flatten(long[] self) Flattens an array. |
|
public static List<Float> |
flatten(float[] self) Flattens an array. |
|
public static List<Double> |
flatten(double[] self) Flattens an array. |
|
public static List<Object> |
flatten(Object[] self) Flattens an array. |
|
public static List<Boolean> |
flatten(boolean self) Flattens a 2D array into a new collection. |
|
public static List<Byte> |
flatten(byte self) Flattens a 2D array into a new collection. |
|
public static List<Character> |
flatten(char self) Flattens a 2D array into a new collection. |
|
public static List<Short> |
flatten(short self) Flattens a 2D array into a new collection. |
|
public static List<Integer> |
flatten(int self) Flattens a 2D array into a new collection. |
|
public static List<Long> |
flatten(long self) Flattens a 2D array into a new collection. |
|
public static List<Float> |
flatten(float self) Flattens a 2D array into a new collection. |
|
public static List<Double> |
flatten(double self) Flattens a 2D array into a new collection. |
|
public static Collection |
flattenMany(Object[] self, Closure<?> transform) Flatten an array. |
|
public static List<Boolean> |
getAt(boolean[] array, Range<?> range) Supports the subscript operator for a boolean array with a range giving the desired indices. |
|
public static List<Byte> |
getAt(byte[] array, Range<?> range) Supports the subscript operator for a byte array with a range giving the desired indices. |
|
public static List<Character> |
getAt(char[] array, Range<?> range) Supports the subscript operator for a char array with a range giving the desired indices. |
|
public static List<Short> |
getAt(short[] array, Range<?> range) Supports the subscript operator for a short array with a range giving the desired indices. |
|
public static List<Integer> |
getAt(int[] array, Range<?> range) Supports the subscript operator for an int array with a range giving the desired indices. |
|
public static List<Long> |
getAt(long[] array, Range<?> range) Supports the subscript operator for a long array with a range giving the desired indices. |
|
public static List<Float> |
getAt(float[] array, Range<?> range) Supports the subscript operator for a float array with a range giving the desired indices. |
|
public static List<Double> |
getAt(double[] array, Range<?> range) Supports the subscript operator for a double array with a range giving the desired indices. |
<T> |
public static List<T> |
getAt(T[] array, Range<?> range) Supports the subscript operator for an object array with a range giving the desired indices. |
|
public static List<Boolean> |
getAt(boolean[] array, IntRange range) Supports the subscript operator for a boolean array with an IntRange giving the desired indices. |
|
public static List<Byte> |
getAt(byte[] array, IntRange range) Supports the subscript operator for a byte array with an IntRange giving the desired indices. |
|
public static List<Character> |
getAt(char[] array, IntRange range) Supports the subscript operator for a char array with an IntRange giving the desired indices. |
|
public static List<Short> |
getAt(short[] array, IntRange range) Supports the subscript operator for a short array with an IntRange giving the desired indices. |
|
public static List<Integer> |
getAt(int[] array, IntRange range) Supports the subscript operator for an int array with an IntRange giving the desired indices. |
|
public static List<Long> |
getAt(long[] array, IntRange range) Supports the subscript operator for a long array with an IntRange giving the desired indices. |
|
public static List<Float> |
getAt(float[] array, IntRange range) Supports the subscript operator for a float array with an IntRange giving the desired indices. |
|
public static List<Double> |
getAt(double[] array, IntRange range) Supports the subscript operator for a double array with an IntRange giving the desired indices. |
<T> |
public static List<T> |
getAt(T[] array, IntRange range) Supports the subscript operator for an object array with an IntRange giving the desired indices. |
|
public static List<Boolean> |
getAt(boolean[] array, ObjectRange range) Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices. |
|
public static List<Byte> |
getAt(byte[] array, ObjectRange range) Supports the subscript operator for a byte array with an ObjectRange giving the desired indices. |
|
public static List<Character> |
getAt(char[] array, ObjectRange range) Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices. |
|
public static List<Short> |
getAt(short[] array, ObjectRange range) Supports the subscript operator for a short array with an ObjectRange giving the desired indices. |
|
public static List<Integer> |
getAt(int[] array, ObjectRange range) Supports the subscript operator for an int array with an ObjectRange giving the desired indices. |
|
public static List<Long> |
getAt(long[] array, ObjectRange range) Supports the subscript operator for a long array with an ObjectRange giving the desired indices. |
|
public static List<Float> |
getAt(float[] array, ObjectRange range) Supports the subscript operator for a float array with an ObjectRange giving the desired indices. |
|
public static List<Double> |
getAt(double[] array, ObjectRange range) Supports the subscript operator for a double array with an ObjectRange giving the desired indices. |
<T> |
public static List<T> |
getAt(T[] array, ObjectRange range) Supports the subscript operator for an object array with an ObjectRange giving the desired indices. |
<T> |
public static List<T> |
getAt(T[] array, EmptyRange<?> range) Supports the subscript operator for an object array with an EmptyRange. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
<T> |
public static 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. |
|
public static IntRange |
getIndices(boolean[] self) Returns indices of the boolean array. |
|
public static IntRange |
getIndices(byte[] self) Returns indices of the byte array. |
|
public static IntRange |
getIndices(char[] self) Returns indices of the char array. |
|
public static IntRange |
getIndices(short[] self) Returns indices of the short array. |
|
public static IntRange |
getIndices(int[] self) Returns indices of the int array. |
|
public static IntRange |
getIndices(long[] self) Returns indices of the long array. |
|
public static IntRange |
getIndices(float[] self) Returns indices of the float array. |
|
public static IntRange |
getIndices(double[] self) Returns indices of the double array. |
<T> |
public static IntRange |
getIndices(T[] self) Returns indices of the array. |
<T> |
public static 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. |
<T> |
public static 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 method used by switch statements. |
<K, T> |
public static Map<K, List<T>> |
groupBy(T[] self, Closure<K> closure) Sorts all array members into groups determined by the supplied mapping closure. |
|
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. |
|
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. |
|
public static boolean |
head(boolean[] self) Returns the first item from the boolean array. |
|
public static byte |
head(byte[] self) Returns the first item from the byte array. |
|
public static char |
head(char[] self) Returns the first item from the char array. |
|
public static short |
head(short[] self) Returns the first item from the short array. |
|
public static int |
head(int[] self) Returns the first item from the int array. |
|
public static long |
head(long[] self) Returns the first item from the long array. |
|
public static float |
head(float[] self) Returns the first item from the float array. |
|
public static double |
head(double[] self) Returns the first item from the double array. |
<T> |
public static T |
head(T[] self) Returns the first item from the Object array. |
|
public static int |
indexOf(Object[] self, Object object) Returns the index of the first occurrence of the specified element in the array. |
|
public static Map<Integer, Integer> |
indexed(int[] self) Zips an int[] with indices in (index, value) order starting from index 0. |
|
public static Map<Integer, Long> |
indexed(long[] self) Zips a long[] with indices in (index, value) order starting from index 0. |
|
public static Map<Integer, Double> |
indexed(double[] self) Zips a double[] with indices in (index, value) order starting from index 0. |
|
public static Map<Integer, Integer> |
indexed(int[] self, int offset) Zips an int[] with indices in (index, value) order. |
|
public static Map<Integer, Long> |
indexed(long[] self, int offset) Zips a long[] with indices in (index, value) order. |
|
public static Map<Integer, Double> |
indexed(double[] self, int offset) Zips a double[] with indices in (index, value) order. |
|
public static boolean[] |
init(boolean[] self) Returns the items from the boolean array excluding the last item. |
|
public static byte[] |
init(byte[] self) Returns the items from the byte array excluding the last item. |
|
public static char[] |
init(char[] self) Returns the items from the char array excluding the last item. |
|
public static short[] |
init(short[] self) Returns the items from the short array excluding the last item. |
|
public static int[] |
init(int[] self) Returns the items from the int array excluding the last item. |
|
public static long[] |
init(long[] self) Returns the items from the long array excluding the last item. |
|
public static float[] |
init(float[] self) Returns the items from the float array excluding the last item. |
|
public static double[] |
init(double[] self) Returns the items from the double array excluding the last item. |
<T> |
public static T[] |
init(T[] self) Returns the items from the Object array excluding the last item. |
<E extends T, T, V extends T> |
public static T |
inject(E[] self, Closure<V> closure) Iterates through the given array, passing the first two elements to the closure. |
<E, T, U extends T, V extends T> |
public static T |
inject(E[] self, U initialValue, Closure<V> closure) Iterates through the given array, passing in the initial value and the first element to the closure. |
<T> |
public static Iterator<T> |
iterator(T[] self) Returns an Iterator which traverses the given array in index order. |
|
public static String |
join(boolean[] self) Concatenates the string representation of each item in this array. |
|
public static String |
join(byte[] self) Concatenates the string representation of each item in this array. |
|
public static String |
join(char[] self) Concatenates the string representation of each item in this array. |
|
public static String |
join(short[] self) Concatenates the string representation of each item in this array. |
|
public static String |
join(int[] self) Concatenates the string representation of each item in this array. |
|
public static String |
join(long[] self) Concatenates the string representation of each item in this array. |
|
public static String |
join(float[] self) Concatenates the string representation of each item in this array. |
|
public static String |
join(double[] self) Concatenates the string representation of each item in this array. |
|
public static String |
join(Object[] self) Concatenates the string representation of each item in this array. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
public static boolean |
last(boolean[] self) Returns the last item from the boolean array. |
|
public static byte |
last(byte[] self) Returns the last item from the byte array. |
|
public static char |
last(char[] self) Returns the last item from the char array. |
|
public static short |
last(short[] self) Returns the last item from the short array. |
|
public static int |
last(int[] self) Returns the last item from the int array. |
|
public static long |
last(long[] self) Returns the last item from the long array. |
|
public static float |
last(float[] self) Returns the last item from the float array. |
|
public static double |
last(double[] self) Returns the last item from the double array. |
<T> |
public static T |
last(T[] self) Returns the last item from the array. |
|
public static int |
lastIndexOf(Object[] self, Object object) Returns the index of the last occurrence of the specified element in the array. |
|
public static int |
max(int[] self) Adds max() method to int arrays. |
|
public static long |
max(long[] self) Adds max() method to long arrays. |
|
public static double |
max(double[] self) Adds max() method to double arrays. |
<T> |
public static T |
max(T[] self) Adds max() method to Object arrays. |
|
public static int |
max(int[] self, IntComparator comparator) Selects the maximum value found from the int array using the supplied IntComparator to determine the maximum of any two values. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
<T> |
public static T |
max(T[] self, Comparator<? super T> comparator) Selects the maximum value found from the Object array using the given comparator. |
<T> |
public static T |
max(T[] self, Closure<?> closure) Selects the maximum value found from the Object array using the closure to determine the correct ordering. |
|
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. |
|
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. |
|
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. |
|
public static int |
min(int[] self) Adds min() method to int arrays. |
|
public static long |
min(long[] self) Adds min() method to long arrays. |
|
public static double |
min(double[] self) Adds min() method to double arrays. |
<T> |
public static T |
min(T[] self) Adds min() method to Object arrays. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
<T> |
public static T |
min(T[] self, Comparator<? super T> comparator) Selects the minimum value found from the Object array using the given comparator. |
<T> |
public static T |
min(T[] self, Closure<?> closure) Selects the minimum value found from the Object array using the closure to determine the correct ordering. |
|
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. |
|
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. |
|
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. |
<T> |
public static 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. |
<T> |
public static 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. |
<T> |
public static T[] |
minus(T[] self, Object removeMe) Creates a new array composed of the elements of the given array minus every occurrence the given object. |
<T> |
public static T[] |
plus(T[] left, Collection<?> right) Creates an array containing elements from an original array plus those from a Collection. |
<T> |
public static T[] |
plus(T[] left, Iterable<?> right) Creates an array containing elements from an original array plus those from an Iterable. |
<T> |
public static T[] |
plus(T[] left, Object[] right) Creates an array as a union of two arrays. |
<T> |
public static T[] |
plus(T[] left, Object right) Creates an array containing elements from an original array plus an additional appended element. |
|
public static boolean[] |
reverse(boolean[] self) Creates a new boolean array containing items which are the same as this array but in reverse order. |
|
public static boolean[] |
reverse(boolean[] self, boolean mutate) Reverses the items in an array. |
|
public static byte[] |
reverse(byte[] self) Creates a new byte array containing items which are the same as this array but in reverse order. |
|
public static byte[] |
reverse(byte[] self, boolean mutate) Reverses the items in an array. |
|
public static char[] |
reverse(char[] self) Creates a new char array containing items which are the same as this array but in reverse order. |
|
public static char[] |
reverse(char[] self, boolean mutate) Reverses the items in an array. |
|
public static short[] |
reverse(short[] self) Creates a new short array containing items which are the same as this array but in reverse order. |
|
public static short[] |
reverse(short[] self, boolean mutate) Reverses the items in an array. |
|
public static int[] |
reverse(int[] self) Creates a new int array containing items which are the same as this array but in reverse order. |
|
public static int[] |
reverse(int[] self, boolean mutate) Reverses the items in an array. |
|
public static long[] |
reverse(long[] self) Creates a new long array containing items which are the same as this array but in reverse order. |
|
public static long[] |
reverse(long[] self, boolean mutate) Reverses the items in an array. |
|
public static float[] |
reverse(float[] self) Creates a new float array containing items which are the same as this array but in reverse order. |
|
public static float[] |
reverse(float[] self, boolean mutate) Reverses the items in an array. |
|
public static double[] |
reverse(double[] self) Creates a new double array containing items which are the same as this array but in reverse order. |
|
public static double[] |
reverse(double[] self, boolean mutate) Reverses the items in an array. |
<T> |
public static T[] |
reverse(T[] self) Creates a new array containing items which are the same as this array but in reverse order. |
<T> |
public static T[] |
reverse(T[] self, boolean mutate) Reverses the items in an array. |
|
public static boolean[] |
reverseEach(boolean[] self, Closure<?> closure) Iterates through a boolean[] in reverse order passing each boolean to the given closure. |
|
public static byte[] |
reverseEach(byte[] self, Closure<?> closure) Iterates through a byte[] in reverse order passing each byte to the given closure. |
|
public static char[] |
reverseEach(char[] self, Closure<?> closure) Iterates through a char[] in reverse order passing each char to the given closure. |
|
public static short[] |
reverseEach(short[] self, Closure<?> closure) Iterates through a short[] in reverse order passing each short to the given closure. |
|
public static int[] |
reverseEach(int[] self, Closure<?> closure) Iterates through an int[] in reverse order passing each int to the given closure. |
|
public static long[] |
reverseEach(long[] self, Closure<?> closure) Iterates through a long[] in reverse order passing each long to the given closure. |
|
public static float[] |
reverseEach(float[] self, Closure<?> closure) Iterates through a float[] in reverse order passing each float to the given closure. |
|
public static double[] |
reverseEach(double[] self, Closure<?> closure) Iterates through a double[] in reverse order passing each double to the given closure. |
<T> |
public static T[] |
reverseEach(T[] self, Closure<?> closure) Iterates over each element of the array in the reverse order. |
<T> |
public static void |
shuffle(T[] self) Randomly reorders the elements of the specified array. |
<T> |
public static void |
shuffle(T[] self, Random rnd) Randomly reorders the elements of the specified array using the specified random instance as the source of randomness. |
<T> |
public static T[] |
shuffled(T[] self) Creates a new array containing the elements of the specified array but in a random order. |
<T> |
public static 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. |
|
public static int |
size(boolean[] self) Provides arrays with a size method similar to collections.
|
|
public static int |
size(byte[] self) Provides arrays with a size method similar to collections. |
|
public static int |
size(char[] self) Provides arrays with a size method similar to collections. |
|
public static int |
size(short[] self) Provides arrays with a size method similar to collections. |
|
public static int |
size(int[] self) Provides arrays with a size method similar to collections. |
|
public static int |
size(long[] self) Provides arrays with a size method similar to collections. |
|
public static int |
size(float[] self) Provides arrays with a size method similar to collections. |
|
public static int |
size(double[] self) Provides arrays with a size method similar to collections. |
|
public static int |
size(Object[] self) Provides the standard Groovy size() method for an array. |
<T> |
public static T[] |
sort(T[] self) Modifies this array so that its elements are in sorted order. |
<T> |
public static T[] |
sort(T[] self, boolean mutate) Sorts the given array into sorted order. |
<T> |
public static T[] |
sort(T[] self, Comparator<? super T> comparator) Sorts the given array into sorted order using the given comparator. |
<T> |
public static 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. |
<T> |
public static 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. |
<T> |
public static 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. |
<T> |
public static Collection<Collection<T>> |
split(T[] self, Closure<?> closure) Splits all items into two collections based on the closure condition. |
|
public static byte |
sum(byte[] self) Sums the items in an array. |
|
public static char |
sum(char[] self) Sums the items in an array. |
|
public static short |
sum(short[] self) Sums the items in an array. |
|
public static int |
sum(int[] self) Sums the items in an array. |
|
public static long |
sum(long[] self) Sums the items in an array. |
|
public static float |
sum(float[] self) Sums the items in an array. |
|
public static double |
sum(double[] self) Sums the items in an array. |
|
public static Object |
sum(Object[] self) Sums the items in an array. |
|
public static byte |
sum(byte[] self, byte initialValue) Sums the items in an array, adding the result to some initial value. |
|
public static char |
sum(char[] self, char initialValue) Sums the items in an array, adding the result to some initial value. |
|
public static short |
sum(short[] self, short initialValue) Sums the items in an array, adding the result to some initial value. |
|
public static int |
sum(int[] self, int initialValue) Sums the items in an array, adding the result to some initial value. |
|
public static long |
sum(long[] self, long initialValue) Sums the items in an array, adding the result to some initial value. |
|
public static float |
sum(float[] self, float initialValue) Sums the items in an array, adding the result to some initial value. |
|
public static double |
sum(double[] self, double initialValue) Sums the items in an array, adding the result to some initial value. |
|
public static Object |
sum(Object[] self, Object initialValue) Sums the items in an array, adding the result to some initial value. |
<T> |
public static Object |
sum(T[] self, Closure<?> closure) Sums the result of applying a closure to each item of an array. |
<T> |
public static 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. |
|
public static boolean[] |
swap(boolean[] self, int i, int j) Swaps two elements at the specified positions. |
|
public static byte[] |
swap(byte[] self, int i, int j) Swaps two elements at the specified positions. |
|
public static char[] |
swap(char[] self, int i, int j) Swaps two elements at the specified positions. |
|
public static short[] |
swap(short[] self, int i, int j) Swaps two elements at the specified positions. |
|
public static int[] |
swap(int[] self, int i, int j) Swaps two elements at the specified positions. |
|
public static long[] |
swap(long[] self, int i, int j) Swaps two elements at the specified positions. |
|
public static float[] |
swap(float[] self, int i, int j) Swaps two elements at the specified positions. |
|
public static double[] |
swap(double[] self, int i, int j) Swaps two elements at the specified positions. |
<T> |
public static T[] |
swap(T[] self, int i, int j) Swaps two elements at the specified positions. |
|
public static boolean[] |
tail(boolean[] self) Returns the items from the boolean array excluding the first item. |
|
public static byte[] |
tail(byte[] self) Returns the items from the byte array excluding the first item. |
|
public static char[] |
tail(char[] self) Returns the items from the char array excluding the first item. |
|
public static short[] |
tail(short[] self) Returns the items from the short array excluding the first item. |
|
public static int[] |
tail(int[] self) Returns the items from the int array excluding the first item. |
|
public static long[] |
tail(long[] self) Returns the items from the long array excluding the first item. |
|
public static float[] |
tail(float[] self) Returns the items from the float array excluding the first item. |
|
public static double[] |
tail(double[] self) Returns the items from the double array excluding the first item. |
<T> |
public static T[] |
tail(T[] self) Returns the items from the array excluding the first item. |
<T> |
public static T[] |
take(T[] self, int num) Returns the first num elements from the head of this array.
|
<T> |
public static T[] |
takeRight(T[] self, int num) Returns the last num elements from the tail of this array.
|
<T> |
public static T[] |
takeWhile(T[] self, Closure<?> condition) Returns the longest prefix of this array where each element passed to the given closure evaluates to true. |
|
public static List<Boolean> |
toList(boolean[] self) Converts this array to a List of the same size, with each element added to the list. |
|
public static List<Byte> |
toList(byte[] self) Converts this array to a List of the same size, with each element added to the list. |
|
public static List<Character> |
toList(char[] self) Converts this array to a List of the same size, with each element added to the list. |
|
public static List<Short> |
toList(short[] self) Converts this array to a List of the same size, with each element added to the list. |
|
public static List<Integer> |
toList(int[] self) Converts this array to a List of the same size, with each element added to the list. |
|
public static List<Long> |
toList(long[] self) Converts this array to a List of the same size, with each element added to the list. |
|
public static List<Float> |
toList(float[] self) Converts this array to a List of the same size, with each element added to the list. |
|
public static List<Double> |
toList(double[] self) Converts this array to a List of the same size, with each element added to the list. |
<T> |
public static List<T> |
toList(T[] self) Converts this array to a List of the same size, with each element added to the list. |
|
public static Set<Boolean> |
toSet(boolean[] self) Converts this array to a Set, with each unique element added to the set. |
|
public static Set<Byte> |
toSet(byte[] self) Converts this array to a Set, with each unique element added to the set. |
|
public static Set<Character> |
toSet(char[] self) Converts this array to a Set, with each unique element added to the set. |
|
public static Set<Short> |
toSet(short[] self) Converts this array to a Set, with each unique element added to the set. |
|
public static Set<Integer> |
toSet(int[] self) Converts this array to a Set, with each unique element added to the set. |
|
public static Set<Long> |
toSet(long[] self) Converts this array to a Set, with each unique element added to the set. |
|
public static Set<Float> |
toSet(float[] self) Converts this array to a Set, with each unique element added to the set. |
|
public static Set<Double> |
toSet(double[] self) Converts this array to a Set, with each unique element added to the set. |
<T> |
public static Set<T> |
toSet(T[] self) Converts this array to a Set, with each unique element added to the set. |
<T> |
public static T[] |
toSorted(T[] self) Returns a sorted version of the given array using the supplied comparator. |
<T> |
public static 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. |
<T> |
public static 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. |
|
public static SpreadMap |
toSpreadMap(Object[] self) Creates a spreadable map from this array. |
|
public static String |
toString(boolean[] self) Returns the string representation of the given array. |
|
public static String |
toString(byte[] self) Returns the string representation of the given array. |
|
public static String |
toString(char[] self) Returns the string representation of the given array. |
|
public static String |
toString(short[] self) Returns the string representation of the given array. |
|
public static String |
toString(int[] self) Returns the string representation of the given array. |
|
public static String |
toString(long[] self) Returns the string representation of the given array. |
|
public static String |
toString(float[] self) Returns the string representation of the given array. |
|
public static String |
toString(double[] self) Returns the string representation of the given array. |
|
public static String |
toString(Object[] self) Returns the string representation of the given array. |
<T> |
public static 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. |
<T> |
public static 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. |
<T> |
public static 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. |
|
public static boolean |
transpose(boolean self) A transpose method for 2D boolean arrays. |
|
public static byte |
transpose(byte self) A transpose method for 2D byte arrays. |
|
public static char |
transpose(char self) A transpose method for 2D char arrays. |
|
public static short |
transpose(short self) A transpose method for 2D short arrays. |
|
public static int |
transpose(int self) A transpose method for 2D int arrays. |
|
public static long |
transpose(long self) A transpose method for 2D long arrays. |
|
public static float |
transpose(float self) A transpose method for 2D float arrays. |
|
public static double |
transpose(double self) A transpose method for 2D double arrays. |
|
public static Object[] |
union(Object[] left, Collection<?> right) Creates an object array containing elements from an original array plus those from a Collection. |
|
public static Object[] |
union(Object[] left, Iterable<?> right) Creates an Object array containing elements from an original array plus those from an Iterable. |
|
public static Object[] |
union(Object[] left, Object[] right) Creates an Object array as a union of two arrays. |
|
public static Object[] |
union(Object[] left, Object right) Creates an Object array containing elements from an original array plus an additional appended element. |
<K, V> |
public static Map<K, V> |
withCollectedKeys(V[] values, Function<? super V, K> keyTransform) A variant of withCollectedKeys for arrays. |
<K, V> |
public static Map<K, V> |
withCollectedKeys(V[] values, Map<K, V> collector, Function<? super V, K> keyTransform) A variant of withCollectedKeys for arrays. |
<K, V> |
public static Map<K, V> |
withCollectedValues(K[] keys, Function<? super K, V> valueTransform) A variant of withCollectedValues for arrays. |
<K, V> |
public static Map<K, V> |
withCollectedValues(K[] keys, Map<K, V> collector, Function<? super K, V> valueTransform) A variant of withCollectedValues for arrays. |
|
public static Iterator<Tuple2<Double, Double>> |
zip(double[] self, double[] other) An iterator of all the pairs of two arrays. |
|
public static Iterator<Tuple2<Float, Float>> |
zip(float[] self, float[] other) An iterator of all the pairs of two arrays. |
|
public static Iterator<Tuple2<Integer, Integer>> |
zip(int[] self, int[] other) An iterator of all the pairs of two arrays. |
|
public static Iterator<Tuple2<Long, Long>> |
zip(long[] self, long[] other) An iterator of all the pairs of two arrays. |
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()
self
- the boolean array over which we iterateIterates 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 }
self
- the boolean array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the byte array over which we iteratepredicate
- the closure predicate used for matchingIterates 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' }
self
- the char array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the char array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the int array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the long array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the float array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the double array over which we iteratepredicate
- the closure predicate used for matchingIterates over the contents of an Array, and checks whether a predicate is valid for at least one element.
self
- the array over which we iteratepredicate
- the closure predicate used for matchingCoerces a boolean array to a boolean value. A boolean array is false if the array is of length 0, and true otherwise.
self
- an arrayCoerces 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
self
- an arrayCoerces a char array to a boolean value. A char array is false if the array is of length 0, and true otherwise.
self
- an arrayCoerces a short array to a boolean value. A short array is false if the array is of length 0, and true otherwise.
self
- an arrayCoerces an int array to a boolean value. An int array is false if the array is of length 0, and true otherwise.
self
- an arrayCoerces a long array to a boolean value. A long array is false if the array is of length 0, and true otherwise.
self
- an arrayCoerces a float array to a boolean value. A float array is false if the array is of length 0, and true otherwise.
self
- an arrayCoerces a double array to a boolean value. A double array is false if the array is of length 0, and true otherwise.
self
- an arrayCoerces an object array to a boolean value. An Object array is false if the array is of length 0. and to true otherwise
self
- the arrayConverts the given array to either a List, Set, or SortedSet. If the given class is something else, the call is deferred to DefaultGroovyMethods.asType.
self
- an arraytype
- the desired classCalculates the average of the bytes in the array.
assert 5.0G == ([2,4,6,8] as byte[]).average()
self
- The array of values to calculate the average ofCalculates the average of the shorts in the array.
assert 5.0G == ([2,4,6,8] as short[]).average()
self
- The array of values to calculate the average ofCalculates the average of the ints in the array.
assert 5.0G == ([2,4,6,8] as int[]).average()
self
- The array of values to calculate the average ofCalculates the average of the longs in the array.
assert 5.0G == ([2,4,6,8] as long[]).average()
self
- The array of values to calculate the average ofCalculates the average of the floats in the array.
assert 5.0d == ([2,4,6,8] as float[]).average()
self
- The array of values to calculate the average ofCalculates the average of the doubles in the array.
assert 5.0d == ([2,4,6,8] as double[]).average()
self
- The array of values to calculate the average ofAverages 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()
self
- The array of values to average 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)
self
- An arrayclosure
- a single parameter closure that returns a (typically) numeric value.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]]
self
- a boolean Array to be choppedchopSizes
- the sizes for the returned piecesChops 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]]
self
- a byte Array to be choppedchopSizes
- the sizes for the returned piecesChops 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]]
self
- a char Array to be choppedchopSizes
- the sizes for the returned piecesChops 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]]
self
- a short Array to be choppedchopSizes
- the sizes for the returned piecesChops 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]]
self
- an int Array to be choppedchopSizes
- the sizes for the returned piecesChops 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]]
self
- a long Array to be choppedchopSizes
- the sizes for the returned piecesChops 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]]
self
- a float Array to be choppedchopSizes
- the sizes for the returned piecesChops 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]]
self
- a double Array to be choppedchopSizes
- the sizes for the returned piecesChops 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.
self
- an Array to be choppedchopSizes
- the sizes for the returned piecesCollates an array.
self
- an arraysize
- the length of each sub-list in the returned listCollates an array into sub-lists.
self
- an arraysize
- the length of each sub-list in the returned liststep
- the number of elements to step through for each sub-listCollates this array into sub-lists.
self
- an arraysize
- the length of each sub-list in the returned listkeepRemainder
- if true, any remaining elements are returned as sub-lists. Otherwise they are discardedCollates this array into sub-lists.
self
- an arraysize
- the length of each sub-list in the returned liststep
- the number of elements to step through for each sub-listkeepRemainder
- if true, any remaining elements are returned as sub-lists. Otherwise they are discarded Iterates through this Array transforming each item into a new value using the
transform
closure, returning a list of transformed values.
self
- an arraytransform
- the closure used to transform each item of the Array 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] Listanswer = [] nums.collect(answer) { it * 2 } assert answer == [2,4,6]
self
- an arraycollector
- the Collection to which the transformed values are addedtransform
- the closure used to transform each itemA variant of collectEntries using the identity closure as the transform.
self
- an arrayA variant of collectEntries using the identity closure as the transform.
self
- an arraycollector
- the Map into which the transformed entries are put 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.
self
- a Collectiontransform
- 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 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.
self
- an arraycollector
- the Map into which the transformed entries are puttransform
- 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 valueA 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]
self
- an arraykeyTransform
- a function for transforming array elements into keysvalueTransform
- a function for transforming array elements into valuesA 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.
self
- an arraycollector
- the Map into which the transformed entries are putkeyTransform
- a function for transforming array elements into keysvalueTransform
- a function for transforming array elements into valuesProjects 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]
self
- an arrayprojection
- a projecting Closure returning a collection of itemsProjects 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]
self
- an arraycollector
- an initial collection to add the projected items toprojection
- a projecting Closure returning a collection of itemsAn iterator of the columns of the array.
double[][] nums = [[1.0d, 2.0d], [10.0d, 20.0d]] assert nums.transpose() == nums.columns().toList()
self
- a double[][]An iterator of the columns of the array.
float[][] nums = [[1.0f, 2.0f], [10.0f, 20.0f]] assert nums.transpose() == nums.columns().toList()
self
- a float[][]An iterator of the columns of the array.
int[][] nums = [[1, 2], [10, 20]] assert nums.transpose() == nums.columns().toList() assert nums.columns().collect{ int[] col -> col.sum() } == [11, 22]
self
- an int[][]An iterator of the columns of the array.
long[][] nums = [[1L, 2L], [10L, 20L]] assert nums.transpose() == nums.columns().toList() assert nums.columns().collect{ long[] col -> col.sum() } == [11L, 22L]
self
- a long[][]Checks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched forChecks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched forChecks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched forChecks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched forChecks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched forChecks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched forChecks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched forChecks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched forChecks whether the array contains the given value.
self
- the array we are searchingvalue
- the value being searched for 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
self
- the array within which we count the number of occurrencesvalue
- the value being searched for 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
self
- the array within which we count the number of occurrencesvalue
- the value being searched for 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
self
- the array within which we count the number of occurrencesvalue
- the value being searched for 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
self
- the array within which we count the number of occurrencesvalue
- the value being searched for 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
self
- the array within which we count the number of occurrencesvalue
- the value being searched for 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
self
- the array within which we count the number of occurrencesvalue
- the value being searched for 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
self
- the array within which we count the number of occurrencesvalue
- the value being searched for 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
self
- the array within which we count the number of occurrencesvalue
- the value being searched for 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)
).
self
- the array within which we count the number of occurrencesvalue
- the value being searched forCounts the number of occurrences which satisfy the given closure from inside this array.
self
- the array within which we count the number of occurrencespredicate
- a closure conditionSorts 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]
self
- an array to group and countclosure
- a closure mapping items to the frequency keysCreates a multiset-like map of the array members.
Example usage:
assert [1:2, 2:2, 3:1] == ([1,2,1,2,3] as Object[]).countBy()
self
- an array to group and countDrops 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[]
self
- the original arraynum
- the number of elements to drop from this arraynum
ones, or else the empty array, if this
array has less than num
elements.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[]
self
- the original arraynum
- the number of elements to drop from this arraynum
ones, or else the empty array, if this
array has less than num
elements.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[]
self
- the original arraycondition
- the closure that must evaluate to true to
continue dropping elementsIterates 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'
self
- the boolean array over which we iterateconsumer
- the consumer for each booleanIterates through a byte[] passing each byte to the given consumer.
byte[] array = [0, 1, 2] String result = '' array.each{ result += it } assert result == '012'
self
- the byte array over which we iterateconsumer
- the consumer for each byteIterates 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'
self
- the char array over which we iterateconsumer
- the consumer for each charIterates through a short[] passing each short to the given consumer.
short[] array = [0, 1, 2] String result = '' array.each{ result += it } assert result == '012'
self
- the short array over which we iterateconsumer
- the consumer for each shortIterates through an int[] passing each int to the given consumer.
int[] array = [0, 1, 2] String result = '' array.each{ result += it } assert result == '012'
self
- the int array over which we iterateconsumer
- the consumer for each intIterates through a long[] passing each long to the given consumer.
long[] array = [0L, 1L, 2L] String result = '' array.each{ result += it } assert result == '012'
self
- the long array over which we iterateconsumer
- the consumer for each longIterates 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'
self
- the float array over which we iterateconsumer
- the consumer for each floatIterates 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'
self
- the double array over which we iterateconsumer
- the consumer for each doubleIterates 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'
self
- the array over which we iterateclosure
- the closure applied on each array entryTraverses through each byte of this byte array.
self
- a byte arrayclosure
- a closureTraverses through each byte of this Byte array. Alias for each.
self
- a Byte arrayclosure
- a closureIterates 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)'
self
- a boolean arrayclosure
- a Closure to operate on each booleanIterates 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)'
self
- a byte arrayclosure
- a Closure to operate on each byteIterates 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)'
self
- a char arrayclosure
- a Closure to operate on each charIterates 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)'
self
- a short arrayclosure
- a Closure to operate on each shortIterates 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)'
self
- an int arrayclosure
- a Closure to operate on each intIterates 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)'
self
- a long arrayclosure
- a Closure to operate on each longIterates 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)'
self
- a float arrayclosure
- a Closure to operate on each floatIterates 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)'
self
- a double arrayclosure
- a Closure to operate on each doubleIterates 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'
self
- an arrayclosure
- a Closure to operate on each array entryCompares 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)
self
- a boolean arrayright
- the array being comparedCompares 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)
self
- a byte arrayright
- the array being comparedCompares 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)
self
- a char arrayright
- the array being comparedCompares 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)
self
- a short arrayright
- the array being comparedCompares 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)
self
- an int arrayright
- the array being comparedCompares 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)
self
- a long arrayright
- the array being comparedCompares 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)
self
- a float arrayright
- the array being comparedCompares 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)
self
- a double arrayright
- the array being compared 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
.
left
- an arrayright
- the List being comparedtrue
if the contents of both collections are equal.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()
self
- the boolean array over which we iterateIterates 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 }
self
- the boolean array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the byte array over which we iteratepredicate
- the closure predicate used for matchingIterates 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' }
self
- the char array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the char array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the int array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the long array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the float array over which we iteratepredicate
- the closure predicate used for matchingIterates 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 }
self
- the double array over which we iteratepredicate
- the closure predicate used for matching Used to determine if the given predicate closure is valid (i.e. returns
true
for all items in this Array).
self
- an arraypredicate
- the closure predicate used for matchingFinds 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 }
self
- an arraycondition
- a closure conditionFinds 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]]
self
- an arrayFinds 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 }
self
- an arraycondition
- a closure conditionIterates over the elements of an array and returns the index of the first item that satisfies the condition specified by the closure.
self
- an arraycondition
- the matching conditionIterates 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.
self
- an arraystartIndex
- start matching from this indexcondition
- the matching conditionIterates over the elements of an array and returns the index values of the items that match the condition specified in the closure.
self
- an arraycondition
- the matching conditionIterates 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.
self
- an arraystartIndex
- start matching from this indexcondition
- the matching conditionReturns 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
self
- an arraycondition
- the matching conditionReturns 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
self
- an arraylowerBound
- the minimum indexcondition
- the matching conditionIterates through the Array stopping once the first non-null result is found and returning that result. If all results are null, null is returned.
self
- an arrayIterates through the Array stopping once the first non-null result is found and returning that result. If all are null, the defaultResult is returned.
self
- an ArraydefaultResult
- an Object that should be returned if all elements are nullIterates 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.
self
- an arraycondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returnedIterates 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.
self
- an arraydefaultResult
- a value that should be returned if all closure results are nullcondition
- a closure that returns a non-null value to indicate that processing should stop and the value should be returnedIterates through the Array collecting any non-null results.
self
- an arrayIterates through the Array transforming items using the supplied closure and collecting any non-null results.
self
- an arrayfilteringTransform
- a closure that should return either a non-null transformed value or null for items which should be discardedReturns the first item from the boolean array.
boolean[] array = [true, false] assert array.first() == trueAn alias for
head()
.self
- an arrayReturns the first item from the byte array.
byte[] bytes = [1, 2, 3] assert bytes.first() == 1An alias for
head()
.self
- an arrayReturns the first item from the char array.
char[] chars = ['a', 'b', 'c'] assert chars.first() == 'a'An alias for
head()
.self
- an arrayReturns the first item from the short array.
short[] shorts = [10, 20, 30] assert shorts.first() == 10An alias for
head()
.self
- an arrayReturns the first item from the int array.
int[] ints = [1, 3, 5] assert ints.first() == 1An alias for
head()
.self
- an arrayReturns the first item from the long array.
long[] longs = [2L, 4L, 6L] assert longs.first() == 2LAn alias for
head()
.self
- an arrayReturns the first item from the float array.
float[] floats = [2.0f, 4.0f, 6.0f] assert floats.first() == 2.0fAn alias for
head()
.self
- an arrayReturns the first item from the double array.
double[] doubles = [10.0d, 20.0d, 30.0d] assert doubles.first() == 10.0dAn alias for
head()
.self
- an arrayReturns the first item from the array.
def array = [3, 4, 2].toArray() assert array.first() == 3
self
- an array 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]
self
- a boolean Array 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]
self
- a byte Array 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']
self
- a char Array 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]
self
- a short Array 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]
self
- an int Array 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]
self
- a long Array to flatten Flattens an array. This array is added to a new collection.
It is an alias for toList()
but allows algorithms to be written which also
work on multidimensional arrays or non-arrays where flattening would be applicable.
float[] array = [0.0f, 1.0f] assert array.flatten() == [0.0f, 1.0f]
self
- a float Array to flatten Flattens an array. This array is added to a new collection.
It is an alias for toList()
but allows algorithms to be written which also
work on multidimensional arrays or non-arrays where flattening would be applicable.
double[] array = [0.0d, 1.0d] assert array.flatten() == [0.0d, 1.0d]
self
- a double Array to flattenFlattens an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.
self
- an Array to flattenFlattens 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]
self
- a 2D boolean ArrayFlattens 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]
self
- a 2D byte ArrayFlattens 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']
self
- a 2D char ArrayFlattens 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]
self
- a 2D short ArrayFlattens 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]
self
- a 2D int ArrayFlattens 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]
self
- a 2D long ArrayFlattens 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]
self
- a 2D float ArrayFlattens 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]
self
- a 2D double ArrayFlatten 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.
self
- an arraytransform
- a transform applied to any leaf elementsSupports 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
array
- a boolean arrayrange
- a range indicating the indices for the items to retrieveSupports 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
array
- a byte arrayrange
- a range indicating the indices for the items to retrieveSupports 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
array
- a char arrayrange
- a range indicating the indices for the items to retrieveSupports 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
array
- a short arrayrange
- a range indicating the indices for the items to retrieveSupports the subscript operator for an int array with a range giving the desired indices.
int[] array = [1, 3, 5, 7, 9, 11] assert array[2..<2] == [] // EmptyRange assert array[(0..5.5).step(2)] == [1, 5, 9] // NumberRange assert array[(1..5.5).step(2)] == [3, 7, 11] // NumberRange
array
- an int arrayrange
- a range indicating the indices for the items to retrieveSupports 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
array
- a long arrayrange
- a range indicating the indices for the items to retrieveSupports 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
array
- a float arrayrange
- a range indicating the indices for the items to retrieveSupports 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
array
- a double arrayrange
- a range indicating the indices for the items to retrieveSupports the subscript operator for an object array with a range giving the desired indices.
array
- an Array of Objectsrange
- a RangeSupports 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]
array
- a boolean arrayrange
- an IntRange indicating the indices for the items to retrieveSupports 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]
array
- a byte arrayrange
- an IntRange indicating the indices for the items to retrieveSupports 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']
array
- a char arrayrange
- an IntRange indicating the indices for the items to retrieveSupports 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]
array
- a short arrayrange
- an IntRange indicating the indices for the items to retrieveSupports 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]
array
- an int arrayrange
- an IntRange indicating the indices for the items to retrieveSupports 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]
array
- a long arrayrange
- an IntRange indicating the indices for the items to retrieveSupports 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]
array
- a float arrayrange
- an IntRange indicating the indices for the items to retrieveSupports 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]
array
- a double arrayrange
- an IntRange indicating the indices for the items to retrieveSupports the subscript operator for an object array with an IntRange giving the desired indices.
array
- an object arrayrange
- an IntRangeSupports 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]
array
- a boolean arrayrange
- an ObjectRange indicating the indices for the items to retrieveSupports 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]
array
- a byte arrayrange
- an ObjectRange indicating the indices for the items to retrieveSupports 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']
array
- a char arrayrange
- an ObjectRange indicating the indices for the items to retrieveSupports 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]
array
- a short arrayrange
- an ObjectRange indicating the indices for the items to retrieveSupports the subscript operator for an int array with an ObjectRange giving the desired indices.
int[] array = [0, 10, 20, 30, 40] def range = new ObjectRange(2, 3) assert array[range] == [20, 30]
array
- an int arrayrange
- an ObjectRange indicating the indices for the items to retrieveSupports 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]
array
- a long arrayrange
- an ObjectRange indicating the indices for the items to retrieveSupports 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]
array
- a float arrayrange
- an ObjectRange indicating the indices for the items to retrieveSupports 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]
array
- a double arrayrange
- an ObjectRange indicating the indices for the items to retrieveSupports the subscript operator for an object array with an ObjectRange giving the desired indices.
array
- an Array of Objectsrange
- an ObjectRangeSupports the subscript operator for an object array with an EmptyRange.
array
- an Array of Objectsrange
- an EmptyRangeSupports 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]
array
- a boolean arrayindices
- a collection of indices for the items to retrieveSupports 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]
array
- a byte arrayindices
- a collection of indices for the items to retrieveSupports 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']
array
- a char arrayindices
- a collection of indices for the items to retrieveSupports 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]
array
- a short arrayindices
- a collection of indices for the items to retrieveSupports the subscript operator for an int array with a (potentially nested) collection giving the desired indices.
int[] array = [0, 2, 4, 6, 8] assert array[2, 3] == [4, 6] assert array[1, 0..1, [0, [-1]]] == [2, 0, 2, 0, 8]
array
- an int arrayindices
- a collection of indices for the items to retrieveSupports 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]
array
- a long arrayindices
- a collection of indices for the items to retrieveSupports 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]
array
- a float arrayindices
- a collection of indices for the items to retrieveSupports 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]
array
- a double arrayindices
- a collection of indices for the items to retrieveSelects a List of items from an array using a Collection to identify the indices to be selected.
array
- an object arrayindices
- a collection of indicesReturns indices of the boolean array.
boolean[] array = [false, true] assert array.indices == 0..1
Returns indices of the byte array.
byte[] array = [0, 1] assert array.indices == 0..1
Returns indices of the char array.
char[] array = 'ab'.chars assert array.indices == 0..1
Returns indices of the short array.
short[] array = [0, 1] assert array.indices == 0..1
Returns indices of the int array.
int[] array = [0, 1] assert array.indices == 0..1
Returns indices of the long array.
long[] array = [0L, 1L] assert array.indices == 0..1
Returns indices of the float array.
float[] array = [0.0f, 1.0f] assert array.indices == 0..1
Returns indices of the double array.
double[] array = [0.0d, 1.0d] assert array.indices == 0..1
Returns indices of the array.
Example:
String[] letters = ['a', 'b', 'c', 'd']
assert 0..<4 == letters.indices
self
- an arrayIterates 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]]
self
- an arrayIterates over the array of items and returns a collection of items that match the given filter - calling the DefaultGroovyMethods.isCase 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 ]
self
- an arrayfilter
- the filter to perform on each element of the array (using the DefaultGroovyMethods.isCase method)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 }
self
- an array to groupclosure
- a closure mapping entries on keysSorts all array members into (sub)groups determined by the supplied mapping closures as per the Iterable variant of this method.
self
- an array to groupclosures
- an array of closures, each mapping entries on keysSorts all array members into (sub)groups determined by the supplied mapping closures as per the list variant of this method.
self
- an array to groupclosures
- a list of closures, each mapping entries on keysReturns the first item from the boolean array.
boolean[] array = [true, false] assert array.head() == trueAn alias for
first()
.self
- an arrayReturns the first item from the byte array.
byte[] bytes = [1, 2, 3] assert bytes.head() == 1An alias for
first()
.self
- an arrayReturns the first item from the char array.
char[] chars = ['a', 'b', 'c'] assert chars.head() == 'a'An alias for
first()
.self
- an arrayReturns the first item from the short array.
short[] shorts = [10, 20, 30] assert shorts.head() == 10An alias for
first()
.self
- an arrayReturns the first item from the int array.
int[] ints = [1, 3, 5] assert ints.head() == 1An alias for
first()
.self
- an arrayReturns the first item from the long array.
long[] longs = [2L, 4L, 6L] assert longs.head() == 2LAn alias for
first()
.self
- an arrayReturns the first item from the float array.
float[] floats = [2.0f, 4.0f, 6.0f] assert floats.head() == 2.0fAn alias for
first()
.self
- an arrayReturns the first item from the double array.
double[] doubles = [10.0d, 20.0d, 30.0d] assert doubles.head() == 10.0dAn alias for
first()
.self
- an arrayReturns the first item from the Object array.
def array = [3, 4, 2].toArray() assert array.head() == 3
self
- an array Returns the index of the first occurrence of the specified element in the
array. That is, the lowest index i
such that
Objects.equals(array[i], object)
or -1 if there is no such index.
String[] array = ['foo','bar','foo'] assert array.indexOf('foo') == 0 assert array.indexOf('bar') == 1 assert array.indexOf('baz') == -1 assert array.indexOf(12345) == -1
Zips an int[] with indices in (index, value) order starting from index 0.
Example usage:int[] nums = [10, 20, 30] assert [0: 10, 1: 20, 2: 30] == nums.indexed()
Zips 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()
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()
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" }
self
- an Iterableoffset
- an index to start fromZips 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)
self
- a long[]offset
- an index to start fromZips 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)
self
- a double[]offset
- an index to start fromReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayIterates through the given array, passing the first two elements to the closure. The result is passed back (injected) to the closure along with the third element and so on until all array elements have been consumed.
def array = new Number[] {1, 2, 3, 4} def value = array.inject { acc, val -> acc * val } assert value == 24 array = new Object[] {['a','b'], ['b','c'], ['d','b']} value = array.inject { acc, val -> acc.intersect(val) } assert value == ['b'] array = new String[] {'t', 'i', 'm'} value = array.inject { acc, val -> acc + val } assert value == 'tim'
self
- an arrayclosure
- a closureIterates through the given array, passing in the initial value and the first element to the closure. The result is sent back (injected) with the second element. The new result is injected back into the closure with the third element and so on until all elements have been consumed.
def array = new Number[] {2, 3, 4} def value = array.inject(1) { acc, val -> acc * val } assert value == 24 array = new Object[] {['a','b'], ['b','c'], ['d','b']} value = array.inject(['a','b','c']) { acc, val -> acc.intersect(val) } assert value == ['b'] array = new String[] {'t', 'i', 'm'} value = array.inject("") { acc, val -> acc + val } assert value == 'tim'
self
- an arrayinitialValue
- base valueclosure
- a closureReturns an Iterator which traverses the given array in index order.
self
- an arrayConcatenates the string representation of each item in this array.
self
- an array of booleanConcatenates the string representation of each item in this array.
self
- an array of byteConcatenates the string representation of each item in this array.
self
- an array of charConcatenates the string representation of each item in this array.
self
- an array of shortConcatenates the string representation of each item in this array.
self
- an array of intConcatenates the string representation of each item in this array.
self
- an array of longConcatenates the string representation of each item in this array.
self
- an array of floatConcatenates the string representation of each item in this array.
self
- an array of doubleConcatenates the string representation of each item in this array.
def array = new Number[]{1,2L,3G} assert array.join() == "123"
self
- an array of ObjectConcatenates the string representation of each item in this array, with the given String as a separator between each item.
self
- an array of booleanseparator
- a String separatorConcatenates the string representation of each item in this array, with the given String as a separator between each item.
self
- an array of byteseparator
- a String separatorConcatenates the string representation of each item in this array, with the given String as a separator between each item.
self
- an array of charseparator
- a String separatorConcatenates the string representation of each item in this array, with the given String as a separator between each item.
self
- an array of shortseparator
- a String separatorConcatenates the string representation of each item in this array, with the given String as a separator between each item.
self
- an array of intseparator
- a String separatorConcatenates the string representation of each item in this array, with the given String as a separator between each item.
self
- an array of longseparator
- a String separatorConcatenates the string representation of each item in this array, with the given String as a separator between each item.
self
- an array of floatseparator
- a String separatorConcatenates the string representation of each item in this array, with the given String as a separator between each item.
self
- an array of doubleseparator
- a String separatorConcatenates 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"
self
- an array of Objectseparator
- a String separatorReturns the last item from the boolean array.
boolean[] array = [true, false, true] assert array.last() == true
self
- an arrayReturns the last item from the byte array.
byte[] bytes = [1, 2, 3] assert bytes.last() == 3
self
- an arrayReturns the last item from the char array.
char[] chars = ['a', 'b', 'c'] assert chars.last() == 'c'
self
- an arrayReturns the last item from the short array.
short[] shorts = [10, 20, 30] assert shorts.last() == 30
self
- an arrayReturns the last item from the int array.
int[] ints = [1, 3, 5] assert ints.last() == 5
self
- an arrayReturns the last item from the long array.
long[] longs = [2L, 4L, 6L] assert longs.last() == 6L
self
- an arrayReturns the last item from the float array.
float[] floats = [2.0f, 4.0f, 6.0f] assert floats.last() == 6.0f
self
- an arrayReturns the last item from the double array.
double[] doubles = [10.0d, 20.0d, 30.0d] assert doubles.last() == 30.0d
self
- an arrayReturns the last item from the array.
def array = [3, 4, 2].toArray() assert array.last() == 2
self
- an array Returns the index of the last occurrence of the specified element in the
array. That is, the highest index i
such that
Objects.equals(array[i], object)
or -1 if there is no such index.
String[] array = ['foo','bar','foo'] assert array.lastIndexOf('foo') == 2 assert array.lastIndexOf('bar') == 1 assert array.lastIndexOf('baz') == -1 assert array.lastIndexOf(12345) == -1
Adds max() method to int arrays.
Example usage:int[] nums = [1, 3, 2] assert 3 == nums.max()
self
- an int arrayAdds max() method to long arrays.
Example usage:long[] nums = [1L, 3L, 2L] assert 3L == nums.max()
self
- a long arrayAdds max() method to double arrays.
Example usage:double[] nums = [1.1d, 3.3d, 2.2d] assert 3.3d == nums.max()
self
- a double arrayAdds max() method to Object arrays.
self
- an arraySelects the maximum value found from the int array using the supplied IntComparator 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() }
self
- an int arraycomparator
- a comparator, i.e. returns a negative value if the first parameter is less than the secondSelects the maximum value found from the int array using the supplier IntUnaryOperator to determine the maximum of any two values. The operator is applied to each array element and the results are compared.
int[] nums = [10, 20, -30] assert 20 == nums.max{ it } assert -30 == nums.max{ it.abs() }
self
- an int arrayoperator
- an operator that returns an int used for comparing valuesSelects 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() }
self
- a long arraycomparator
- a comparator, i.e. returns a negative value if the first parameter is less than the secondSelects 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() }
self
- a long arrayoperator
- an operator that returns a long used for comparing valuesSelects 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() }
self
- a double arraycomparator
- a comparator, i.e. returns a negative value if the first parameter is less than the secondSelects 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 }
self
- a double arrayoperator
- an operator that returns a double used for comparing valuesSelects the maximum value found from the Object array using the given comparator.
self
- an arraycomparator
- a ComparatorSelects 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.
self
- an arrayclosure
- a Closure used to determine the correct orderingSelects the maximum value found from the int array using the comparator to determine the maximum of any two values.
int[] nums = [10, 20, 30] assert 30 == nums.maxComparing(Comparator.naturalOrder()) assert 10 == nums.maxComparing(Comparator.reverseOrder())
self
- an int arraycomparator
- a ComparatorSelects 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())
self
- a long arraycomparator
- a ComparatorSelects 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())
self
- a double arraycomparator
- a ComparatorAdds min() method to int arrays.
Example usage:int[] nums = [20, 10, 30] assert 10 == nums.min()
self
- an int arrayAdds min() method to long arrays.
Example usage:long[] nums = [20L, 10L, 30L] assert 10L == nums.min()
self
- a long arrayAdds min() method to double arrays.
Example usage:double[] nums = [20.0d, 10.0d, 30.0d] assert 10.0d == nums.min()
self
- a double arrayAdds min() method to Object arrays.
self
- an arraySelects 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() }
self
- an int arraycomparator
- a comparator, i.e. returns a negative value if the first parameter is less than the secondSelects the minimum value found from the int array using the supplier IntUnaryOperator to determine the minimum of any two values. The operator is applied to each array element and the results are compared.
int[] nums = [10, -20, 30] assert -20L == nums.min{ n->
n } assert 10L == nums.min{ n->
n.abs() }
self
- an int arrayoperator
- an operator that returns an int used for comparing valuesSelects 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() }
self
- a long arraycomparator
- a comparator, i.e. returns a negative value if the first parameter is less than the secondSelects 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() }
self
- a long arrayoperator
- an operator that returns a long used for comparing valuesSelects 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() }
self
- a double arraycomparator
- a comparator, i.e. returns a negative value if the first parameter is less than the secondSelects 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() }
self
- a double arrayoperator
- an operator that returns a double used for comparing valuesSelects the minimum value found from the Object array using the given comparator.
self
- an arraycomparator
- a ComparatorSelects 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.
self
- an arrayclosure
- a Closure used to determine the correct orderingSelects the minimum value found from the int array using the comparator to determine the minimum of any two values.
int[] nums = [1, 2, 3] assert 1 == nums.minComparing(Comparator.naturalOrder()) assert 3 == nums.minComparing(Comparator.reverseOrder())
self
- an int arraycomparator
- a ComparatorSelects 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())
self
- a long arraycomparator
- a ComparatorSelects 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())
self
- a double arraycomparator
- a ComparatorCreates 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[]
self
- an arrayremoveMe
- an Iterable of elements to removeCreates 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[]
self
- an arrayremoveMe
- an array of elements to removeCreates 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[]
self
- an arrayremoveMe
- an element to remove from the arrayCreates 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()] }
left
- the arrayright
- a Collection to be appendedCreates 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'}
left
- the arrayright
- an Iterable to be appendedCreates 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 }
left
- the left Arrayright
- the right ArrayCreates 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() }
left
- the arrayright
- the value to appendCreates 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]
self
- a boolean arrayReverses 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]
self
- a boolean arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdCreates 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
self
- a byte arrayReverses 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
self
- a byte arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdCreates 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[]
self
- a char arrayReverses 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']
self
- a char arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdCreates 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
self
- a short arrayReverses 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
self
- a short arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdCreates 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
self
- an int arrayReverses 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
self
- an int arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdCreates 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
self
- a long arrayReverses 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
self
- a long arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdCreates 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]
self
- a float arrayReverses 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
self
- a float arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdCreates 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]
self
- a double arrayReverses 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
self
- a double arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdCreates a new array containing items which are the same as this array but in reverse order.
self
- an arrayReverses 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
self
- an arraymutate
- true
if the array itself should be reversed in place, false
if a new array should be createdIterates 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'
self
- the boolean array over which we iterateclosure
- the closure applied on each booleanIterates 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'
self
- the byte array over which we iterateclosure
- the closure applied on each byteIterates 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'
self
- the char array over which we iterateclosure
- the closure applied on each charIterates 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'
self
- the short array over which we iterateclosure
- the closure applied on each shortIterates 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'
self
- the int array over which we iterateclosure
- the closure applied on each intIterates 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'
self
- the long array over which we iterateclosure
- the closure applied on each longIterates 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'
self
- the float array over which we iterateclosure
- the closure applied on each floatIterates 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'
self
- the double array over which we iterateclosure
- the closure applied on each doubleIterates over each element of the array in the reverse order.
self
- an arrayclosure
- a closure to which each item is passedRandomly 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) }
self
- an arrayRandomly 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) }
self
- an arrayCreates a new array containing the elements of the specified array but in a random order.
Integer[] array = [10, 5, 20] def result = array.shuffled() assert array !== result assert array.length == result.length assert array.every{ result.contains(it) } assert array == new Integer[] {10, 5, 20}
self
- an arrayCreates 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[] array = [10, 5, 20] def result = array.shuffled(r) assert array !== result assert array.length == result.length assert array.every{ result.contains(it) } assert array == new Integer[] {10, 5, 20}
self
- an array Provides arrays with a size
method similar to collections.
boolean[] array = [true, false, true] assert array.size() == 3
self
- a boolean array Provides arrays with a size
method similar to collections.
self
- a byte array Provides arrays with a size
method similar to collections.
self
- a char array Provides arrays with a size
method similar to collections.
self
- a short array Provides arrays with a size
method similar to collections.
self
- an int array Provides arrays with a size
method similar to collections.
self
- a long array Provides arrays with a size
method similar to collections.
self
- a float array Provides arrays with a size
method similar to collections.
self
- a double array Provides the standard Groovy size()
method for an array.
self
- an object arrayModifies this array so that its elements are in sorted order. The array items are assumed to be comparable.
self
- the array to be sortedSorts 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[]
self
- the array to be sortedmutate
- false will always cause a new array to be created, true will mutate the array in placeSorts the given array into sorted order using the given comparator.
self
- the array to be sortedcomparator
- a Comparator used for the comparisonModifies 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[]
self
- the array containing elements to be sortedmutate
- false will always cause a new array to be created, true will mutate arrays in placecomparator
- a Comparator used for the comparisonSorts 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.
self
- the array containing the elements to be sortedclosure
- a Closure used to determine the correct orderingModifies 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[]
self
- the array to be sortedmutate
- false will always cause a new array to be created, true will mutate arrays in placeclosure
- a Closure used to determine the correct orderingSplits 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.
self
- an Arrayclosure
- a closure conditionSums the items in an array.
assert (1+2+3+4 as byte) == ([1,2,3,4] as byte[]).sum()
self
- The array of values to add togetherSums the items in an array.
assert (1+2+3+4 as char) == ([1,2,3,4] as char[]).sum()
self
- The array of values to add togetherSums the items in an array.
assert (1+2+3+4 as short) == ([1,2,3,4] as short[]).sum()
self
- The array of values to add togetherSums the items in an array.
assert 1+2+3+4 == ([1,2,3,4] as int[]).sum()
self
- The array of values to add togetherSums the items in an array.
assert (1+2+3+4 as long) == ([1,2,3,4] as long[]).sum()
self
- The array of values to add togetherSums the items in an array.
assert (1+2+3+4 as float) == ([1,2,3,4] as float[]).sum()
self
- The array of values to add togetherSums the items in an array.
assert (1+2+3+4 as double) == ([1,2,3,4] as double[]).sum()
self
- The array of values to add togetherSums the items in an array. This is equivalent to invoking the "plus" method on all items in the array.
self
- The array of values to add togetherSums 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)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial valueSums 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)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial valueSums 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)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial valueSums 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)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial valueSums 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)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial valueSums 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)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial valueSums 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)
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial valueSums the items in an array, adding the result to some initial value.
self
- an array of values to suminitialValue
- the items in the array will be summed to this initial value Sums the result of applying a closure to each item of an array.
array.sum(closure)
is equivalent to:
array.collect(closure).sum()
.
self
- An arrayclosure
- a single parameter closure that returns a (typically) numeric value. 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)
.
self
- an arrayclosure
- a single parameter closure that returns a (typically) numeric value.initialValue
- the closure results will be summed to this initial valueSwaps two elements at the specified positions.
Example:
assert ([false, true, false, true] as boolean[]) == ([false, false, true, true] as boolean[]).swap(1, 2)
self
- a boolean arrayi
- a positionj
- a positionSwaps two elements at the specified positions.
Example:
assert ([1, 3, 2, 4] as byte[]) == ([1, 2, 3, 4] as byte[]).swap(1, 2)
self
- a boolean arrayi
- a positionj
- a positionSwaps two elements at the specified positions.
Example:
assert ([1, 3, 2, 4] as char[]) == ([1, 2, 3, 4] as char[]).swap(1, 2)
self
- a boolean arrayi
- a positionj
- a positionSwaps two elements at the specified positions.
Example:
assert ([1, 3, 2, 4] as short[]) == ([1, 2, 3, 4] as short[]).swap(1, 2)
self
- a boolean arrayi
- a positionj
- a positionSwaps two elements at the specified positions.
Example:
assert ([1, 3, 2, 4] as int[]) == ([1, 2, 3, 4] as int[]).swap(1, 2)
self
- a boolean arrayi
- a positionj
- a positionSwaps two elements at the specified positions.
Example:
assert ([1, 3, 2, 4] as long[]) == ([1, 2, 3, 4] as long[]).swap(1, 2)
self
- a boolean arrayi
- a positionj
- a positionSwaps two elements at the specified positions.
Example:
assert ([1, 3, 2, 4] as float[]) == ([1, 2, 3, 4] as float[]).swap(1, 2)
self
- a boolean arrayi
- a positionj
- a positionSwaps two elements at the specified positions.
Example:
assert ([1, 3, 2, 4] as double[]) == ([1, 2, 3, 4] as double[]).swap(1, 2)
self
- a boolean arrayi
- a positionj
- a positionSwaps two elements at the specified positions.
Example:
assert (["a", "c", "b", "d"] as String[]) == (["a", "b", "c", "d"] as String[]).swap(1, 2)
self
- an arrayi
- a positionj
- a positionReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an array 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[]
self
- the original arraynum
- the number of elements to take from this arraynum
elements of this array,
or else the whole array if it has less than num
elements. 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[]
self
- the original arraynum
- the number of elements to take from this arraynum
elements of this array,
or else the whole array if it has less than num
elements.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[]
self
- the original arraycondition
- the closure that must evaluate to true to
continue taking elementsConverts this array to a List of the same size, with each element added to the list.
self
- a boolean arrayConverts this array to a List of the same size, with each element added to the list.
self
- a byte arrayConverts this array to a List of the same size, with each element added to the list.
self
- a char arrayConverts this array to a List of the same size, with each element added to the list.
self
- a short arrayConverts this array to a List of the same size, with each element added to the list.
self
- an int arrayConverts this array to a List of the same size, with each element added to the list.
self
- a long arrayConverts this array to a List of the same size, with each element added to the list.
self
- a float arrayConverts this array to a List of the same size, with each element added to the list.
self
- a double arrayConverts this array to a List of the same size, with each element added to the list.
self
- an object arrayConverts 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
self
- a boolean arrayConverts 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
self
- a byte arrayConverts 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
self
- a char arrayConverts 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
self
- a short arrayConverts 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
self
- an int arrayConverts 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
self
- a long arrayConverts 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
self
- a float arrayConverts 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
self
- a double arrayConverts this array to a Set, with each unique element added to the set.
self
- an object arrayReturns a sorted version of the given array using the supplied comparator.
self
- the array to be sortedReturns 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]
self
- the array to be sortedcomparator
- a Comparator used for the comparisonSorts 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.
self
- the array containing the elements to be sortedclosure
- a Closure used to determine the correct orderingCreates a spreadable map from this array.
self
- an object arrayReturns the string representation of the given array.
boolean[] array = [false, true, false] assert array.toString() == '[false, true, false]'
self
- an arrayReturns the string representation of the given array.
byte[] array = [1, 2, 3, 2, 1] assert array.toString() == '[1, 2, 3, 2, 1]'
self
- an arrayReturns the string representation of the given array.
char[] array = 'abcd'.chars assert array instanceof char[] assert array.toString() == 'abcd'
self
- an arrayReturns the string representation of the given array.
short[] array = [1, 2, 3, 2, 1] assert array.toString() == '[1, 2, 3, 2, 1]'
self
- an arrayReturns the string representation of the given array.
int[] array = [1, 2, 3, 2, 1] assert array.toString() == '[1, 2, 3, 2, 1]'
self
- an arrayReturns the string representation of the given array.
long[] array = [1, 2, 3, 2, 1] assert array.toString() == '[1, 2, 3, 2, 1]'
self
- an arrayReturns 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]'
self
- an arrayReturns 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]'
self
- an arrayReturns the string representation of the given array.
self
- an arrayReturns 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
self
- an arrayReturns 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
self
- an arraycomparator
- a Comparator used to determine unique (equal) items
If null
, the Comparable natural ordering of the elements will be used.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
self
- an arrayclosure
- a Closure used to determine unique itemsA 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
self
- a 2D boolean arrayA 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
self
- a 2D byte arrayA 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
self
- a 2D char arrayA 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
self
- a 2D short arrayA 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
self
- a 2D int arrayA 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
self
- a 2D long arrayA 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
self
- a 2D float arrayA 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
self
- a 2D double arrayCreates 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'}
left
- the arrayright
- a Collection to be appendedCreates 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'}
left
- the arrayright
- an Iterable to be appendedCreates 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'}
left
- the left Arrayright
- the right ArrayCreates 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'}
left
- the arrayright
- the value to appendA variant of withCollectedKeys for arrays.
values
- an arraykeyTransform
- a function for transforming array elements into valuesA variant of withCollectedKeys for arrays.
values
- an arraycollector
- the Map into which the transformed entries are putkeyTransform
- a function for transforming array elements into valuesA variant of withCollectedValues for arrays.
keys
- an arrayvalueTransform
- a function for transforming array elements into valuesA variant of withCollectedValues for arrays.
keys
- an arraycollector
- the Map into which the transformed entries are putvalueTransform
- a function for transforming array elements into valuesAn iterator of all the pairs of two arrays.
double[] small = [1.0d, 2.0d, 3.0d] double[] large = [100d, 200d, 300d] assert [small, large].transpose() == small.zip(large).toList()
self
- a double[]other
- another double[]An iterator of all the pairs of two arrays.
float[] small = [1.0f, 2.0f, 3.0f] float[] large = [100f, 200f, 300f] assert [small, large].transpose() == small.zip(large).toList()
self
- a float[]other
- another float[]An iterator of all the pairs of two arrays.
int[] small = [1, 2, 3] int[] large = [100, 200, 300] assert [101, 202, 303] == small.zip(large).collect{ a, b -> a + b } assert [small, large].transpose() == small.zip(large).toList()
self
- an int[]other
- another int[]An iterator of all the pairs of two arrays.
long[] small = [1L, 2L, 3L] long[] large = [100L, 200L, 300L] assert [101L, 202L, 303L] == small.zip(large).collect{ a, b -> a + b } assert [small, large].transpose() == small.zip(large).toList()
self
- a long[]other
- another long[]