Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK

## java.lang
Class Object[]

Method Summary
`boolean` | `asBoolean()` Coerce an Object array to a boolean value.
`Object` | `asType(Class clazz)` Converts the given array to either a List, Set, or SortedSet.
`Map` | `collectEntries(Map result, Closure closure)` Iterates through this array transforming each item using the closure as a transformer into a map entry, returning a map of the transformed entries.
`Map` | `collectEntries(Closure closure)` Iterates through this array transforming each item using the closure as a transformer into a map entry, returning a map of the transformed entries.
`Number` | `count(Object value)` Counts the number of occurrences of the given value inside this array.
`boolean` | `equals(List right)` Determines if the contents of this array are equal to the contents of the given list, in the same order.
`Object` | `first()` Returns the first item from the Object array.
`Collection` | `flatten()` Flatten an array.
`List` | `getAt(Collection indices)` Select a List of items from an Object array using a Collection to identify the indices to be selected.
`List` | `getAt(Range range)` Support the range subscript operator for an Array
`List` | `getAt(IntRange range)`
`List` | `getAt(EmptyRange range)`
`List` | `getAt(ObjectRange range)`
`Object` | `head()` Returns the first item from the Object array.
`Object` | `inject(Object initialValue, Closure closure)` Iterates through the given array, passing in the initial value to the closure along with the first item.
`Iterator` | `iterator()` Attempts to create an Iterator for the given object by first converting it to a Collection.
`String` | `join(String separator)` Concatenates the `toString()` representation of each items in this array, with the given String as a separator between each item.
`Object` | `last()` Returns the last item from the Object array.
`Object` | `max()` Adds max() method to Object arrays.
`Object` | `max(Closure closure)` Selects the maximum value found from the Object array using the closure to determine the correct ordering.
`Object` | `max(Comparator comparator)` Selects the maximum value found from the Object array using the given comparator.
`Object` | `min()` Adds min() method to Object arrays.
`Object` | `min(Comparator comparator)` Selects the minimum value found from the Object array using the given comparator.
`Object` | `min(Closure closure)` Selects the minimum value found from the Object array using the closure to determine the correct ordering.
`Object[]` | `minus(Collection removeMe)` Create an array composed of the elements of the first array minus the elements of the given collection.
`Object[]` | `minus(Object[] removeMe)` Create an array composed of the elements of the first array minus the elements of the given array.
`Object[]` | `minus(Object operand)` Create a new object array composed of the elements of the first array minus the operand.
`Object[]` | `reverse()` Reverse the items in an Object array.
`Object[]` | `reverseEach(Closure closure)` Iterate over each element of the array in the reverse order.
`int` | `size()` Provide the standard Groovy `size()` method for an array.
`Object[]` | `sort()` Sorts the given Object array into sorted order.
`Object[]` | `sort(Comparator comparator)` Sorts the given Object array into sorted order using the given comparator.
`Object[]` | `sort(Closure closure)` Sorts the given Object array into a newly created array using the Closure to determine the correct ordering.
`Object` | `sum()` Sums the items in an array.
`Object` | `sum(Object initialValue)` Sums the items in an array, adding the result to some initial value.
`Object` | `sum(Closure closure)` Sums the result of apply a closure to each item of an array.
`Object` | `sum(Object initialValue, Closure closure)` Sums the result of applying a closure to each item of an array to some initial value.
`Object[]` | `tail()` Returns the items from the Object array excluding the first item.
`String` | `toArrayString()` Returns the string representation of the given array.
`List` | `toList()` Allows conversion of arrays into a mutable List.
`SpreadMap` | `toSpreadMap()` Creates a spreadable map from this array.
`String` | `toString()` Returns the string representation of this array's contents.

Method Detail

### asBoolean

    public boolean asBoolean()

  Coerce an Object array to a boolean value. An Object array is false if the array is of length 0. and to true otherwise

Returns:
  the boolean value

Since:
  1.7.0

### asType

    public Object asType(Class clazz)

  Converts the given array to either a List, Set, or SortedSet. If the given class is something else, the call is deferred to {link #asType(Object,Class)}.

Parameters:
  `clazz` - the desired class.

Returns:
  the object resulting from this type conversion

Since:
  1.5.1

See:
  Object#asType.

### collectEntries

    public Map collectEntries(Map result, Closure closure)

  Iterates through this array transforming each item using the closure as a transformer into a map entry, returning a map of the 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']

Parameters:
  `result` - the Map into which the collected entries are put.
  `closure` - the closure used for mapping, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value.

Returns:
  a Map of the transformed entries

Since:
  1.7.9

See:
  Map#collect(Collection, Closure).

### collectEntries

    public Map collectEntries(Closure closure)

  Iterates through this array transforming each item using the closure as a transformer into a map entry, returning a map of the 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']

Parameters:
  `closure` - the closure used for mapping, which has an item from self as the parameter and should return a Map.Entry, a Map or a two-element list containing the resulting key and value.

Returns:
  a Map of the transformed entries

Since:
  1.7.9

See:
  Collection#collectEntries(Map, Closure).

### count

    public Number count(Object value)

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

Parameters:
  `value` - the value being searched for.

Returns:
  the number of occurrences

Since:
  1.6.4

### equals

    public boolean equals(List right)

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

Parameters:
  `right` - the list being compared.

Returns:
  true if the contents of both collections are equal

Since:
  1.5.0

### first

    public Object first()

  Returns the first item from the Object array.

      def array = [3, 4, 2].toArray()
      assert array.first() == 3

Returns:
  the first item from the Object array

Since:
  1.7.3

### flatten

    public Collection flatten()

  Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

Returns:
  a flattened Collection

Since:
  1.6.0

### getAt

    public List getAt(Collection indices)

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

Parameters:
  `indices` - a Collection of indices.

Returns:
  a new list of the values at the given indices

Since:
  1.0

### getAt

    public List getAt(Range range)

  Support the range subscript operator for an Array

Parameters:
  `range` - a Range.

Returns:
  a range of a list from the range's from index up to but not including the range's to value

Since:
  1.0

### getAt

    public List getAt(IntRange range)

Parameters:
  `range` - an IntRange.

Returns:
  a range of a list from the range's from index up to but not including the range's to value

Since:
  1.0

### getAt

    public List getAt(EmptyRange range)

Parameters:
  `range` - an EmptyRange.

Returns:
  an empty Range

Since:
  1.5.0

### getAt

    public List getAt(ObjectRange range)

Parameters:
  `range` - an ObjectRange.

Returns:
  a range of a list from the range's from index up to but not including the range's to value

Since:
  1.0

### head

    public Object head()

  Returns the first item from the Object array.

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

Returns:
  the first item from the Object array

Since:
  1.7.3

### inject

    public Object inject(Object initialValue, Closure closure)

  Iterates through the given array, passing in the initial value to the closure along with the first item. The result is passed back (injected) into the closure along with the second item. The new result is injected back into the closure along with the third item and so on until all elements of the array have been used. Also known as foldLeft in functional parlance.

Parameters:
  `initialValue` - an initialValue.
  `closure` - a closure.

Returns:
  the last value of the last iteration

Since:
  1.5.0

### iterator

    public Iterator iterator()

  Attempts to create an Iterator for the given object by first converting it to a Collection.

Returns:
  an Iterator for the given Array.

Since:
  1.6.4

See:
  DefaultTypeTransformation#asCollection.

### join

    public String join(String separator)

  Concatenates the `toString()` representation of each items in this array, with the given String as a separator between each item.

Parameters:
  `separator` - a String separator.

Returns:
  the joined String

Since:
  1.0

### last

    public Object last()

  Returns the last item from the Object array.

      def array = [3, 4, 2].toArray()
      assert array.last() == 2

Returns:
  the last item from the Object array

Since:
  1.7.3

### max

    public Object max()

  Adds max() method to Object arrays.

Returns:
  the maximum value

Since:
  1.5.5

See:
  Collection#max.

### max

    public Object max(Closure closure)

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

Parameters:
  `closure` - a Closure used to determine the correct ordering.

Returns:
  the maximum value

Since:
  1.5.5

See:
  Collection#max.

### max

    public Object max(Comparator comparator)

  Selects the maximum value found from the Object array using the given comparator.

Parameters:
  `comparator` - a Comparator.

Returns:
  the maximum value

Since:
  1.5.5

### min

    public Object min()

  Adds min() method to Object arrays.

Returns:
  the minimum value

Since:
  1.5.5

See:
  Collection#min.

### min

    public Object min(Comparator comparator)

  Selects the minimum value found from the Object array using the given comparator.

Parameters:
  `comparator` - a Comparator.

Returns:
  the minimum value

Since:
  1.5.5

See:
  Collection#min.

### min

    public Object min(Closure closure)

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

Parameters:
  `closure` - a Closure used to determine the correct ordering.

Returns:
  the minimum value

Since:
  1.5.5

See:
  Collection#min.

### minus

    public Object[] minus(Collection removeMe)

  Create an array composed of the elements of the first array minus the elements of the given collection.

Parameters:
  `removeMe` - a Collection of elements to remove.

Returns:
  an array with the supplied elements removed

Since:
  1.5.5

### minus

    public Object[] minus(Object[] removeMe)

  Create an array composed of the elements of the first array minus the elements of the given array.

Parameters:
  `removeMe` - an array of elements to remove.

Returns:
  an array with the supplied elements removed

Since:
  1.5.5

### minus

    public Object[] minus(Object operand)

  Create a new object array composed of the elements of the first array minus the operand.

Parameters:
  `operand` - an element to remove from the array.

Returns:
  a new array with the operand removed

Since:
  1.5.5

### reverse

    public Object[] reverse()

  Reverse the items in an Object array.

Returns:
  an array containing the reversed items

Since:
  1.5.5

### reverseEach

    public Object[] reverseEach(Closure closure)

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

Parameters:
  `closure` - a closure to which each item is passed.

Returns:
  the original array

Since:
  1.5.2

### size

    public int size()

  Provide the standard Groovy `size()` method for an array.

Returns:
  the size (length) of the Array

Since:
  1.0

### sort

    public Object[] sort()

  Sorts the given Object array into sorted order. The array items are assumed to be comparable.

Returns:
  the sorted array

Since:
  1.5.5

### sort

    public Object[] sort(Comparator comparator)

  Sorts the given Object array into sorted order using the given comparator.

Parameters:
  `comparator` - a Comparator used for the comparison.

Returns:
  the sorted array

Since:
  1.5.5

### sort

    public Object[] sort(Closure closure)

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

Parameters:
  `closure` - a Closure used to determine the correct ordering.

Returns:
  the sorted array

Since:
  1.5.5

### sum

    public Object sum()

  Sums the items in an array. This is equivalent to invoking the "plus" method on all items in the array.

Returns:
  The sum of all of the items

Since:
  1.7.1

See:
  Collection#sum.

### sum

    public Object sum(Object initialValue)

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

Parameters:
  `initialValue` - the items in the array will be summed to this initial value.

Returns:
  The sum of all of the items.

Since:
  1.7.1

### sum

    public Object sum(Closure closure)

  Sums the result of apply a closure to each item of an array. `array.sum(closure)` is equivalent to: `array.collect(closure).sum()`.

Parameters:
  `closure` - a single parameter closure that returns a numeric value..

Returns:
  The sum of the values returned by applying the closure to each item of the array.

Since:
  1.7.1

### sum

    public Object sum(Object initialValue, Closure closure)

  Sums the result of applying a closure to each item of an array to some initial value. `array.sum(initVal, closure)` is equivalent to: `array.collect(closure).sum(initVal)`.

Parameters:
  `closure` - a single parameter closure that returns a numeric value..
  `initialValue` - the closure results will be summed to this initial value.

Returns:
  The sum of the values returned by applying the closure to each item of the array.

Since:
  1.7.1

### tail

    public Object[] tail()

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

          String[] strings = ["a", "b", "c"]
          def result = strings.tail()
          assert strings.class.componentType == String

Returns:
  an Object array without its first element

Since:
  1.7.3

### toArrayString

    public String toArrayString()

  Returns the string representation of the given array. The string displays the contents of the array, similar to an array literal, i.e. `{1, 2, "a"}`.

Returns:
  the string representation

Since:
  1.0

### toList

    public List toList()

  Allows conversion of arrays into a mutable List.

Returns:
  the array as a List

Since:
  1.0

### toSpreadMap

    public SpreadMap toSpreadMap()

  Creates a spreadable map from this array.

Returns:
  a newly created Spreadmap

Since:
  1.0

See:
  SpreadMap#SpreadMap.

### toString

    public String toString()

  Returns the string representation of this array's contents.

Returns:
  the string representation

Since:
  1.0

See:
  Object[]#toArrayString.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK