Package: primitives

## [Java] Class boolean[]

- primitives.boolean[]

-     public class boolean[]
      extends Object

  GDK enhancements for boolean[].

  displayName:
    boolean[]
  receiverFqcn:
    boolean[]

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public boolean` | `any()` Iterates over the contents of a boolean Array, and checks whether any element is true.
    `` | `public boolean` | `any(Closure<?> predicate)` Iterates over the contents of a boolean Array, and checks whether a predicate is valid for at least one element.
    `` | `public boolean` | `asBoolean()` Coerces a boolean array to a boolean value.
    `` | `public List<List<Boolean>>` | `chop(int chopSizes)` Chops the boolean array into pieces, returning lists with sizes corresponding to the supplied chop sizes.
    `` | `public boolean` | `contains(Object value)` Checks whether the array contains the given value.
    `` | `public Number` | `count(Object value)` Counts the number of occurrences of the given value inside this array.
    `` | `public boolean[]` | `each(Consumer<Boolean> consumer)` Iterates through a boolean[] passing each boolean to the given consumer.
    `` | `public boolean[]` | `each(Closure<?> closure)` Iterates through a boolean[] passing each boolean to the given closure.
    `` | `public boolean[]` | `eachWithIndex(Closure<?> closure)` Iterates through a boolean[], passing each boolean and the element's index (a counter starting at zero) to the given closure.
    `` | `public boolean` | `equals(boolean[] right)` Compares the contents of this array to the contents of the given array.
    `` | `public boolean` | `every()` Iterates over the contents of a boolean Array, and checks whether every element is true.
    `` | `public boolean` | `every(Closure<?> predicate)` Iterates over the contents of a boolean Array, and checks whether a predicate is valid for every element.
    `` | `public boolean` | `first()` Returns the first item from the boolean array.
    `` | `public List<Boolean>` | `flatten()` Flattens an array.
    `` | `public List<Boolean>` | `getAt(Range<?> range)` Supports the subscript operator for a boolean array with a range giving the desired indices.
    `` | `public List<Boolean>` | `getAt(IntRange range)` Supports the subscript operator for a boolean array with an IntRange giving the desired indices.
    `` | `public List<Boolean>` | `getAt(ObjectRange range)` Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices.
    `` | `public List<Boolean>` | `getAt(Collection<?> indices)` Supports the subscript operator for a boolean array with a (potentially nested) collection giving the desired indices.
    `` | `public IntRange` | `getIndices()` Returns indices of the boolean array.
    `` | `public String` | `groovyToString()` Returns Groovy's list-like string representation for a boolean array.
    `` | `public boolean` | `head()` Returns the first item from the boolean array.
    `` | `public boolean[]` | `init()` Returns the items from the boolean array excluding the last item.
    `` | `public String` | `join()` Concatenates the string representation of each item in this array.
    `` | `public String` | `join(String separator)` Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    `` | `public boolean` | `last()` Returns the last item from the boolean array.
    `` | `public void` | `putAt(IntRange range, boolean[] source)` A helper method to allow arrays to be set with subscript operators.
    `` | `public void` | `putAt(IntRange range, Iterable<Boolean> source)` A helper method to allow arrays to be set with subscript operators.
    `` | `public boolean[]` | `reverse()` Creates a new boolean array containing items which are the same as this array but in reverse order.
    `` | `public boolean[]` | `reverse(boolean mutate)` Reverses the items in an array.
    `` | `public boolean[]` | `reverseEach(Closure<?> closure)` Iterates through a boolean[] in reverse order passing each boolean to the given closure.
    `` | `public int` | `size()` Provides arrays with a `size` method similar to collections.
    `` | `public Stream<Boolean>` | `stream()` Returns a sequential Stream with the specified array as its source.
    `` | `public boolean[]` | `swap(int i, int j)` Swaps two elements at the specified positions.
    `` | `public boolean[]` | `tail()` Returns the items from the boolean array excluding the first item.
    `` | `public List<Boolean>` | `toImmutableList()` Converts this array to an immutable List of the same size, with each element added to the list.
    `` | `public Set<Boolean>` | `toImmutableSet()` Converts this array to an immutable Set, with each unique element added to the set.
    `` | `public List<Boolean>` | `toList()` Converts this array to a List of the same size, with each element added to the list.
    `` | `public Set<Boolean>` | `toSet()` Converts this array to a Set, with each unique element added to the set.
    `` | `public String` | `toString()` Returns the string representation of the given array.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `addShutdownHook, any, any, asBoolean, asType, clamp, clamp, collect, collect, collect, dump, each, eachMatch, eachMatch, eachWithIndex, every, every, find, find, findAll, findAll, findIndexOf, findIndexOf, findIndexValues, findIndexValues, findLastIndexOf, findLastIndexOf, findResult, findResult, findResult, findResult, getAt, getMetaClass, getMetaPropertyValues, getProperties, grep, grep, hasProperty, identity, inject, inject, inject, inject, inspect, invokeMethod, is, isCase, isNotCase, iterator, metaClass, print, print, printf, printf, println, println, println, putAt, respondsTo, respondsTo, setMetaClass, sleep, sleep, split, sprintf, sprintf, stream, takeIf, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits`

- - ### Method Detail

    - #### public boolean any()

      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()

      Returns:
        true if any boolean is true
      Since:
        5.0.0

    - #### public boolean any(Closure<?> predicate)

      Iterates over the contents of a boolean Array, and checks whether a predicate is valid for at least one element.

           boolean[] array = [true]
           assert array.any{ it }
           assert !array.any{ !it }

      Parameters:
        `predicate` - the closure predicate used for matching
      Returns:
        true if any iteration for the booleans matches the closure predicate
      Since:
        5.0.0

    - #### public boolean asBoolean()

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

      Returns:
        the array's boolean value
      Since:
        1.7.4

    - #### public List<List<Boolean>> chop(int chopSizes)

      Chops the boolean array into pieces, returning lists with sizes corresponding to the supplied chop sizes. If the array isn't large enough, truncated (possibly empty) pieces are returned. Using a chop size of -1 will cause that piece to contain all remaining items from the array.

           boolean[] array = [false, true, false]
           assert array.chop(1, 2) == [[false], [true, false]]

      Parameters:
        `chopSizes` - the sizes for the returned pieces
      Returns:
        a list of lists chopping the original array elements into pieces determined by chopSizes
      See Also:
        ArrayGroovyMethods#collate(Object[], int)#collate(Object[], int)
      Since:
        5.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`).

           boolean[] array = [false, true, true]
           assert array.count(true) == 2

      Parameters:
        `value` - the value being searched for
      Returns:
        the number of occurrences
      See Also:
        DefaultGroovyMethods#count(Iterator, Object)#count(Iterator, Object)
      Since:
        1.6.4

    - #### public boolean[] each(Consumer<Boolean> consumer)

      Iterates through a boolean[] passing each boolean to the given consumer.

           boolean[] array = [false, true, false]
           String result = ''
           array.each{ result += it.toString()[0] }
           assert result == 'ftf'

      Parameters:
        `consumer` - the consumer for each boolean
      Returns:
        the self array
      Since:
        5.0.0

    - #### public boolean[] each(Closure<?> closure)

      Iterates through a boolean[] passing each boolean to the given closure.

           boolean[] array = [false, true, false]
           String result = ''
           array.each{ result += it.toString()[0] }
           assert result == 'ftf'

      Parameters:
        `closure` - the closure applied on each boolean
      Returns:
        the self array
      Since:
        6.0.0

    - #### public boolean[] eachWithIndex(Closure<?> closure)

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

           boolean[] array = [false, true, false]
           String result = ''
           array.eachWithIndex{ item, index -> result += "$index($item)" }
           assert result == '0(false)1(true)2(false)'

      Parameters:
        `closure` - a Closure to operate on each boolean
      Returns:
        the self array
      Since:
        5.0.0

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

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

      Example usage:

           boolean[] array1 = [true, false]
           boolean[] array2 = [true, false]
           assert array1 !== array2
           assert array1.equals(array2)

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

    - #### public boolean every()

      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()

      Returns:
        true if no boolean is false
      Since:
        5.0.0

    - #### public boolean every(Closure<?> predicate)

      Iterates over the contents of a boolean Array, and checks whether a predicate is valid for every element.

           boolean[] array = [true]
           assert array.every{ it }
           assert !array.every{ !it }

      Parameters:
        `predicate` - the closure predicate used for matching
      Returns:
        true if the predicate returns true for all elements in the array
      Since:
        5.0.0

    - #### public boolean first()

      Returns the first item from the boolean array.

           boolean[] array = [true, false]
           assert array.first() == true

      An alias for `head()`.
      throws:
        NoSuchElementException if the array is empty
      Returns:
        the first element
      Since:
        5.0.0

    - #### public List<Boolean> 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.

           boolean[] array = [false, true]
           assert array.flatten() == [false, true]

      Returns:
        a Collection of the array elements
      Since:
        1.6.0

    - #### public List<Boolean> getAt(Range<?> range)

      Supports the subscript operator for a boolean array with a range giving the desired indices.

           boolean[] array = [false, true, false, true, false, true]
           assert array[2..<2] == [] // EmptyRange
           assert array[(0..5.5).step(2)] == [false, false, false] // NumberRange
           assert array[(1..5.5).step(2)] == [true, true, true]    // NumberRange

      Parameters:
        `range` - a range indicating the indices for the items to retrieve
      Returns:
        list of the retrieved booleans
      Since:
        1.0

    - #### public List<Boolean> getAt(IntRange range)

      Supports the subscript operator for a boolean array with an IntRange giving the desired indices.

           boolean[] array = [false, false, true, true, false]
           assert array[2..3] == [true, true]
           assert array[-2..-1] == [true, false]
           assert array[-1..-2] == [false, true]

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

    - #### public List<Boolean> getAt(ObjectRange range)

      Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices.

           boolean[] array = [false, false, true, true, false]
           def range = new ObjectRange(2, 3)
           assert array[range] == [true, true]

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

    - #### public List<Boolean> getAt(Collection<?> indices)

      Supports the subscript operator for a boolean array with a (potentially nested) collection giving the desired indices.

           boolean[] array = [false, false, true, true, false]
           assert array[2, 3] == [true, true]
           assert array[0, 0..1, [1, [-1]]] == [false, false, false, false, false]

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

    - #### public IntRange getIndices()

      Returns indices of the boolean array.

           boolean[] array = [false, true]
           assert array.indices == 0..1

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

    - #### public String groovyToString()

      Returns Groovy's list-like string representation for a boolean array.

      If disabled, e.g. via `-Dgroovy.extension.disable=groovyToString(boolean[])`, the JDK's default array `toString()` is used instead.

      Returns:
        the string representation
      Since:
        6.0.0

    - #### public boolean head()

      Returns the first item from the boolean array.

           boolean[] array = [true, false]
           assert array.head() == true

      An alias for `first()`.
      throws:
        NoSuchElementException if the array is empty
      Returns:
        the first element
      Since:
        5.0.0

    - #### public boolean[] init()

      Returns the items from the boolean array excluding the last item.

           boolean[] array = [true, false, true]
           def result = array.init()
           assert result == [true, false]
           assert array.class.componentType == result.class.componentType

      throws:
        UnsupportedOperationException if the array is empty
      Returns:
        an array without its last element
      Since:
        5.0.0

    - #### public String join()

      Concatenates the string representation of each item in this array.

      Returns:
        the joined String
      Since:
        5.0.0

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

      Concatenates the string representation of each item 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 boolean last()

      Returns the last item from the boolean array.

           boolean[] array = [true, false, true]
           assert array.last() == true

      throws:
        NoSuchElementException if the array is empty
      Returns:
        the last element
      Since:
        5.0.0

    - #### public void putAt(IntRange range, boolean[] source)

      A helper method to allow arrays to be set with subscript operators.

           boolean[] from = [true, true, true]
           boolean[] to = [false, false, false, false, false]
           to[1..3] = from
           assert to == [false, true, true, true, false]

      throws:
        IndexOutOfBoundsException if the source doesn't have sufficient elements or the IntRange is too big for the self array
      Parameters:
        `range` - the subset of the array to set
        `source` - the source array from which new values will come
      Since:
        5.0.0

    - #### public void putAt(IntRange range, Iterable<Boolean> source)

      A helper method to allow arrays to be set with subscript operators. False will be used if the source iterable has insufficient elements.

           def from = [true, true, true]
           boolean[] to = [false, false, false, false, false]
           to[1..3] = from
           assert to == [false, true, true, true, false]

      Parameters:
        `range` - the subset of the array to set
        `source` - the source array from which new values will come
      Since:
        5.0.0

    - #### public boolean[] reverse()

      Creates a new boolean array containing items which are the same as this array but in reverse order.

           boolean[] array = [false, true]
           assert array.reverse() == [true, false]

      Returns:
        an array containing the reversed items
      See Also:
        reverse(boolean[], boolean)
      Since:
        5.0.0

    - #### public boolean[] reverse(boolean mutate)

      Reverses the items in an array. If mutate is true, the original array is modified in place and returned. Otherwise, a new array containing the reversed items is produced.

           boolean[] array = [false, true, true]
           def yarra = array.reverse(true)
           assert array == [true, true, false]
           assert yarra == [true, true, false]
           assert array === yarra
           yarra = array.reverse(false)
           assert array !== yarra
           assert array == [true, true, false]
           assert yarra == [false, true, true]

      Parameters:
        `mutate` - `true` if the array itself should be reversed in place, `false` if a new array should be created
      Returns:
        an array containing the reversed items
      Since:
        5.0.0

    - #### public boolean[] reverseEach(Closure<?> closure)

      Iterates through a boolean[] in reverse order passing each boolean to the given closure.

           boolean[] array = [false, true, true]
           String result = ''
           array.reverseEach{ result += it }
           assert result == 'truetruefalse'

      Parameters:
        `closure` - the closure applied on each boolean
      Returns:
        the self array
      Since:
        5.0.0

    - #### public int size()

      Provides arrays with a `size` method similar to collections.

           boolean[] array = [true, false, true]
           assert array.size() == 3

      Returns:
        the length of the array
      Since:
        1.5.0

    - #### public Stream<Boolean> stream()

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

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

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

      Swaps two elements at the specified positions.

      Example:

           assert ([false, true, false, true] as boolean[]) == ([false, false, true, true] as boolean[]).swap(1, 2)

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

    - #### public boolean[] tail()

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

           boolean[] array = [true, false, true]
           def result = array.tail()
           assert result == [false, true]
           assert array.class.componentType == result.class.componentType

      throws:
        UnsupportedOperationException if the array is empty
      Returns:
        an array without its first element
      Since:
        5.0.0

    - #### public List<Boolean> toImmutableList()

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

      Returns:
        An immutable list containing the contents of this array.
      Since:
        6.0.0

    - #### public Set<Boolean> toImmutableSet()

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

           boolean[] array = [true, false, true]
           Set expected = [true, false]
           assert array.toImmutableSet() == expected

      Returns:
        An immutable set containing the unique contents of this array.
      Since:
        6.0.0

    - #### public List<Boolean> 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.6.0

    - #### public Set<Boolean> toSet()

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

           boolean[] array = [true, false, true]
           Set expected = [true, false]
           assert array.toSet() == expected

      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.

           boolean[] array = [false, true, false]
           assert array.toString() == '[false, true, false]'

      Returns:
        the string representation
      Since:
        1.6.0