Package: primitives-and-primitive-arrays

## Class int[]

- - ### Methods Summary

    Methods
    Return type | Name and parameters
    --- | ---
    `boolean` | `asBoolean()` Coerces an int array to a boolean value.
    `BigDecimal` | `average()` Calculates the average of the ints in the array.
    `boolean` | `contains(Object value)` Checks whether the array contains the given value.
    `Number` | `count(Object value)` Counts the number of occurrences of the given value inside this array.
    `boolean` | `equals(int[] right)` Compare the contents of this array to the contents of the given array.
    `Collection` | `flatten()` Flatten an array.
    `List` | `getAt(IntRange range)` Support the subscript operator with an IntRange for an int array
    `List` | `getAt(ObjectRange range)` Support the subscript operator with an ObjectRange for an int array
    `List` | `getAt(Range range)` Support the subscript operator with a range for an int array
    `List` | `getAt(Collection indices)` Support the subscript operator with a collection for an int array
    `IntRange` | `getIndices()` Returns indices of the int array.
    `Map` | `indexed()` Zips an int[] with indices in (index, value) order starting from index 0.
    `Map` | `indexed(int offset)` Zips an int[] with indices in (index, value) order.
    `IntStream` | `intStream()` Returns a sequential IntStream with the specified array as its source.
    `String` | `join(String separator)` Concatenates the string representation of each items in this array, with the given String as a separator between each item.
    `int` | `max()` Adds max() method to int arrays.
    `int` | `min()` Adds min() method to int arrays.
    `int` | `size()` Allows arrays to behave similar to collections.
    `Stream` | `stream()` Returns a sequential Stream with the specified array as its source.
    `int` | `sum()` Sums the items in an array.
    `int` | `sum(int initialValue)` Sums the items in an array, adding the result to some initial value.
    `int[]` | `swap(int i, int j)` Swaps two elements at the specified positions.
    `List` | `toList()` Converts this array to a List of the same size, with each element added to the list.
    `Set` | `toSet()` Converts this array to a Set, with each unique element added to the set.
    `String` | `toString()` Returns the string representation of the given array.

- - ### Methods Detail

    - #### public boolean asBoolean()

      Coerces an int array to a boolean value. An int array is false if the array is of length 0, and true otherwise.

      Returns:
        the array's boolean value
      Since:
        1.7.4

    - #### public BigDecimal average()

      Calculates the average of the ints in the array.

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

      Returns:
        The average of the items
      Since:
        3.0.0

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

      Checks whether the array contains the given value.

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

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

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

      Parameters:
        `value` - the value being searched for
      Returns:
        the number of occurrences
      Since:
        1.6.4

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

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

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

    - #### 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

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

      Support the subscript operator with an IntRange for an int array

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

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

      Support the subscript operator with an ObjectRange for an int array

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

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

      Support the subscript operator with a range for an int array

      Parameters:
        `range` - a range indicating the indices for the items to retrieve
      Returns:
        list of the ints at the given indices
      Since:
        1.0

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

      Support the subscript operator with a collection for an int array

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

    - #### public IntRange getIndices()

      Returns indices of the int array.

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

    - #### public Map indexed()

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

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

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

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

      Example usage:

          int[] nums = [10, 20, 30]
          assert [5: 10, 6: 20, 7: 30] == nums.indexed(5)
          assert ["1: 10", "2: 20", "3: 30"] == nums.indexed(1).collect { idx, str -> "$idx: $str" }

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

    - #### public IntStream intStream()

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

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

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

      Concatenates the string 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:
        2.4.1

    - #### public int max()

      Adds max() method to int arrays.

      Returns:
        the maximum value
      Since:
        3.0.8
      See Also:
        Object[]#max()

    - #### public int min()

      Adds min() method to int arrays.

      Example usage:

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

      Returns:
        the minimum value
      Since:
        3.0.8
      See Also:
        Object[]#min()

    - #### public int size()

      Allows arrays to behave similar to collections.

      Returns:
        the length of the array
      Since:
        1.0
      See Also:
        Array#getLength(java.lang.Object)

    - #### public Stream stream()

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

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

    - #### public int sum()

      Sums the items in an array.

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

      Returns:
        The sum of all of the items
      Since:
        2.4.2

    - #### public int sum(int initialValue)

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

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

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

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

      Swaps two elements at the specified positions.

      Example:

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

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

    - #### public List toList()

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

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

    - #### public Set toSet()

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

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

    - #### public String toString()

      Returns the string representation of the given array.

      Returns:
        the string representation
      Since:
        1.6.0