Scala Standard Library2.13.18 < Back


# Packages

-  package root

  This is the documentation for the Scala standard library.

  This is the documentation for the Scala standard library.

  #### Package structure

  The scala package contains core types like `Int`, `Float`, `Array` or `Option` which are accessible in all Scala compilation units without explicit qualification or imports.

  Notable packages include:

  - `scala.collection` and its sub-packages contain Scala's collections framework
    - `scala.collection.immutable` - Immutable, sequential data-structures such as `Vector`, `List`, `Range`, `HashMap` or `HashSet`
    - `scala.collection.mutable` - Mutable, sequential data-structures such as `ArrayBuffer`, `StringBuilder`, `HashMap` or `HashSet`
    - `scala.collection.concurrent` - Mutable, concurrent data-structures such as `TrieMap`
  - `scala.concurrent` - Primitives for concurrent programming such as `Futures` and `Promises`
  - `scala.io` - Input and output operations
  - `scala.math` - Basic math functions and additional numeric types like `BigInt` and `BigDecimal`
  - `scala.sys` - Interaction with other processes and the operating system
  - `scala.util.matching` - Regular expressions

  Other packages exist. See the complete list on the right.

  Additional parts of the standard library are shipped as separate libraries. These include:

  - `scala.reflect` - Scala's reflection API (scala-reflect.jar)
  - `scala.xml` - XML parsing, manipulation, and serialization (scala-xml.jar)
  - `scala.collection.parallel` - Parallel collections (scala-parallel-collections.jar)
  - `scala.util.parsing` - Parser combinators (scala-parser-combinators.jar)
  - `scala.swing` - A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)

  #### Automatic imports

  Identifiers in the scala package and the `scala.Predef` object are always in scope by default.

  Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example, `List` is an alias for `scala.collection.immutable.List`.

  Other aliases refer to classes provided by the underlying platform. For example, on the JVM, `String` is an alias for `java.lang.String`.

  Definition Classes
    root
-  package scala

  Core Scala types.

  Core Scala types. They are always available without an explicit import.

  Definition Classes
    root
-  package collection
  Definition Classes
    scala
-  package concurrent
  Definition Classes
    collection
-  package convert
  Definition Classes
    collection
-  package generic
  Definition Classes
    collection
-  package immutable
  Definition Classes
    collection
-  package mutable
  Definition Classes
    collection
- +:
- :+
- AbstractIndexedSeqView
- AbstractIterable
- AbstractIterator
- AbstractMap
- AbstractMapView
- AbstractSeq
- AbstractSeqView
- AbstractSet
- AbstractView
- AnyStepper
- ArrayOps
- BitSet
- BitSetOps
- BufferedIterator
- BuildFrom
- BuildFromLowPriority1
- BuildFromLowPriority2
- ClassTagIterableFactory
- ClassTagSeqFactory
- DefaultMap
- DoubleStepper
- EvidenceIterableFactory
- EvidenceIterableFactoryDefaults
- Factory
- Hashing
- IndexedSeq
- IndexedSeqOps
- IndexedSeqView
- IntStepper
- Iterable
- IterableFactory
- IterableFactoryDefaults
- IterableOnce
- IterableOnceExtensionMethods
- IterableOnceOps
- IterableOps
- Iterator
- JavaConverters
- LazyZip2
- LazyZip3
- LazyZip4
- LinearSeq
- LinearSeqOps
- LongStepper
- Map
- MapFactory
- MapFactoryDefaults
- MapOps
- MapView
- MapViewFactory
- Searching
- Seq
- SeqFactory
- SeqMap
- SeqOps
- SeqView
- Set
- SetOps
- SortedIterableFactory
- SortedMap
- SortedMapFactory
- SortedMapFactoryDefaults
- SortedMapOps
- SortedOps
- SortedSet
- SortedSetFactoryDefaults
- SortedSetOps
- SpecificIterableFactory
- Stepper
- StepperShape
- StepperShapeLowPriority1
- StepperShapeLowPriority2
- StrictOptimizedClassTagSeqFactory
- StrictOptimizedIterableOps
- StrictOptimizedLinearSeqOps
- StrictOptimizedMapOps
- StrictOptimizedSeqFactory
- StrictOptimizedSeqOps
- StrictOptimizedSetOps
- StrictOptimizedSortedMapOps
- StrictOptimizedSortedSetOps
- StringOps
- StringView
- View
- WithFilter

c

scala.collection

# ArrayOps

###
Companion object ArrayOps

#### final class ArrayOps[A] extends AnyVal

This class serves as a wrapper for `Array`s with many of the operations found in indexed sequences. Where needed, instances of arrays are implicitly converted into this class. There is generally no reason to create an instance explicitly or use an `ArrayOps` type. It is better to work with plain `Array` types instead and rely on the implicit conversion to `ArrayOps` when calling a method (which does not actually allocate an instance of `ArrayOps` because it is a value class).

Neither `Array` nor `ArrayOps` are proper collection types (i.e. they do not extend `Iterable` or even `IterableOnce`). `mutable.ArraySeq` and `immutable.ArraySeq` serve this purpose.

The difference between this class and `ArraySeq`s is that calling transformer methods such as `filter` and `map` will yield an array, whereas an `ArraySeq` will remain an `ArraySeq`.

A

  type of the elements contained in this array.

Source
  ArrayOps.scala

Linear Supertypes
AnyVal, Any
Type Hierarchy

Ordering

1. Alphabetic
2. By Inheritance

Inherited

1. ArrayOps
2. AnyVal
3. Any

Implicitly

1. by any2stringadd
2. by StringFormat
3. by Ensuring
4. by ArrowAssoc

1. Hide All
2. Show All

Visibility

1. Public
2. Protected

### Instance Constructors

1.  new ArrayOps(xs: Array[A])

### Value Members

1.  final def !=(arg0: Any): Boolean

   Test two objects for inequality.

   Test two objects for inequality.

   returns

     `true` if !(this == that), false otherwise.

   Definition Classes
     Any
2.  final def ##: Int

   Equivalent to `x.hashCode` except for boxed numeric types and `null`.

   Equivalent to `x.hashCode` except for boxed numeric types and `null`. For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them. For `null` returns a hashcode where `null.hashCode` throws a `NullPointerException`.

   returns

     a hash value consistent with ==

   Definition Classes
     Any
3.  def +(other: String): String
   Implicit
     This member is added by an implicit conversion from ArrayOps[A] toany2stringadd[ArrayOps[A]] performed by method any2stringadd in scala.Predef.
   Definition Classes
     any2stringadd
4.  final def ++[B >: A](xs: Array[_ <: B])(implicit arg0: ClassTag[B]): Array[B]
   Annotations
     @inline()
5.  final def ++[B >: A](xs: IterableOnce[B])(implicit arg0: ClassTag[B]): Array[B]
   Annotations
     @inline()
6.  final def ++:[B >: A](prefix: Array[_ <: B])(implicit arg0: ClassTag[B]): Array[B]
   Annotations
     @inline()
7.  final def ++:[B >: A](prefix: IterableOnce[B])(implicit arg0: ClassTag[B]): Array[B]
   Annotations
     @inline()
8.  final def +:[B >: A](x: B)(implicit arg0: ClassTag[B]): Array[B]
   Annotations
     @inline()
9.  def ->[B](y: B): (ArrayOps[A], B)
   Implicit
     This member is added by an implicit conversion from ArrayOps[A] toArrowAssoc[ArrayOps[A]] performed by method ArrowAssoc in scala.Predef.
   Definition Classes
     ArrowAssoc
   Annotations
     @inline()
10.  final def :+[B >: A](x: B)(implicit arg0: ClassTag[B]): Array[B]
    Annotations
      @inline()
11.  final def :++[B >: A](suffix: Array[_ <: B])(implicit arg0: ClassTag[B]): Array[B]
    Annotations
      @inline()
12.  final def :++[B >: A](suffix: IterableOnce[B])(implicit arg0: ClassTag[B]): Array[B]
    Annotations
      @inline()
13.  final def ==(arg0: Any): Boolean

    Test two objects for equality.

    Test two objects for equality. The expression `x == that` is equivalent to `if (x eq null) that eq null else x.equals(that)`.

    returns

      `true` if the receiver object is equivalent to the argument; `false` otherwise.

    Definition Classes
      Any
14.  def appended[B >: A](x: B)(implicit arg0: ClassTag[B]): Array[B]

    A copy of this array with an element appended.

15.  def appendedAll[B >: A](suffix: Array[_ <: B])(implicit arg0: ClassTag[B]): Array[B]

    A copy of this array with all elements of an array appended.

16.  def appendedAll[B >: A](suffix: IterableOnce[B])(implicit arg0: ClassTag[B]): Array[B]

    A copy of this array with all elements of a collection appended.

17.  final def asInstanceOf[T0]: T0

    Forces the compiler to treat the receiver object as having type `T0`, even though doing so may violate type safety.

    Forces the compiler to treat the receiver object as having type `T0`, even though doing so may violate type safety.

    This method is useful when you believe you have type information the compiler doesn't, and it also isn't possible to check the type at runtime. In such situations, skipping type safety is the only option.

    It is platform dependent whether `asInstanceOf` has any effect at runtime. It might do a runtime type test on the erasure of `T0`, insert a conversion (such as boxing/unboxing), fill in a default value, or do nothing at all.

    In particular, `asInstanceOf` is not a type test. It does **not** mean:

        this match {
         case x: T0 => x
         case _     => throw ClassCastException("...")

    Use pattern matching or isInstanceOf for type testing instead.

    Situations where `asInstanceOf` is useful:

    - when flow analysis fails to deduce `T0` automatically
    - when down-casting a type parameter or an abstract type member (which cannot be checked at runtime due to type erasure) If there is any doubt and you are able to type test instead, you should do so.

    Be careful of using `asInstanceOf` when `T0` is a primitive type. When `T0` is primitive, `asInstanceOf` may insert a conversion instead of a type test. If your intent is to convert, use a `toT` method (`x.toChar`, `x.toByte`, etc.).

    returns

      the receiver object.

    Definition Classes
      Any
    Exceptions thrown

      `ClassCastException` if the receiver is not an instance of the erasure of `T0`, if that can be checked on this platform

18.  def collect[B](pf: PartialFunction[A, B])(implicit arg0: ClassTag[B]): Array[B]

    Builds a new array by applying a partial function to all elements of this array on which the function is defined.

    Builds a new array by applying a partial function to all elements of this array on which the function is defined.

    B

      the element type of the returned array.

    pf

      the partial function which filters and maps the array.

    returns

      a new array resulting from applying the given partial function `pf` to each element on which it is defined and collecting the results. The order of the elements is preserved.

19.  def collectFirst[B](pf: PartialFunction[A, B]): Option[B]

    Finds the first element of the array for which the given partial function is defined, and applies the partial function to it.

20.  def combinations(n: Int): Iterator[Array[A]]

    Iterates over combinations of elements.

    Iterates over combinations of elements.

    A combination of length `n` is a sequence of `n` elements selected in order of their first index in this sequence.

    For example, `"xyx"` has two combinations of length 2. The `x` is selected first: `"xx"`, `"xy"`. The sequence `"yx"` is not returned as a combination because it is subsumed by `"xy"`.

    If there is more than one way to generate the same combination, only one will be returned.

    For example, the result `"xy"` arbitrarily selected one of the `x` elements.

    As a further illustration, `"xyxx"` has three different ways to generate `"xy"` because there are three elements `x` to choose from. Moreover, there are three unordered pairs `"xx"` but only one is returned.

    It is not specified which of these equal combinations is returned. It is an implementation detail that should not be relied on. For example, the combination `"xx"` does not necessarily contain the first `x` in this sequence. This behavior is observable if the elements compare equal but are not identical.

    As a consequence, `"xyx".combinations(3).next()` is `"xxy"`: the combination does not reflect the order of the original sequence, but the order in which elements were selected, by "first index"; the order of each `x` element is also arbitrary.

    returns

      An Iterator which traverses the n-element combinations of this array

    Example:

    1.     Array('a', 'b', 'b', 'b', 'c').combinations(2).map(runtime.ScalaRunTime.stringOf).foreach(println)
           // Array(a, b)
           // Array(a, c)
           // Array(b, b)
           // Array(b, c)
           Array('b', 'a', 'b').combinations(2).map(runtime.ScalaRunTime.stringOf).foreach(println)
           // Array(b, b)
           // Array(b, a)

21.  final def concat[B >: A](suffix: Array[_ <: B])(implicit arg0: ClassTag[B]): Array[B]
    Annotations
      @inline()
22.  final def concat[B >: A](suffix: IterableOnce[B])(implicit arg0: ClassTag[B]): Array[B]
    Annotations
      @inline()
23.  def contains(elem: A): Boolean

    Tests whether this array contains a given value as an element.

    Tests whether this array contains a given value as an element.

    elem

      the element to test.

    returns

      `true` if this array has an element that is equal (as determined by `==`) to `elem`, `false` otherwise.

24.  def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Int

    Copy elements of this array to another array.

    Copy elements of this array to another array. Fills the given array `xs` starting at index `start` with at most `len` values. Copying will stop once either all the elements of this array have been copied, or the end of the array is reached, or `len` elements have been copied.

    B

      the type of the elements of the array.

    xs

      the array to fill.

    start

      the starting index within the destination array.

    len

      the maximal number of elements to copy.

25.  def copyToArray[B >: A](xs: Array[B], start: Int): Int

    Copy elements of this array to another array.

    Copy elements of this array to another array. Fills the given array `xs` starting at index `start`. Copying will stop once either all the elements of this array have been copied, or the end of the array is reached.

    B

      the type of the elements of the array.

    xs

      the array to fill.

    start

      the starting index within the destination array.

26.  def copyToArray[B >: A](xs: Array[B]): Int

    Copy elements of this array to another array.

    Copy elements of this array to another array. Fills the given array `xs` starting at index 0. Copying will stop once either all the elements of this array have been copied, or the end of the array is reached.

    B

      the type of the elements of the array.

    xs

      the array to fill.

27.  def count(p: (A) => Boolean): Int

    Counts the number of elements in this array which satisfy a predicate

28.  def diff[B >: A](that: Seq[B]): Array[A]

    Computes the multiset difference between this array and another sequence.

    Computes the multiset difference between this array and another sequence.

    that

      the sequence of elements to remove

    returns

      a new array which contains all elements of this array except some of occurrences of elements that also appear in `that`. If an element value `x` appears n times in `that`, then the first n occurrences of `x` will not form part of the result, but any following occurrences will.

29.  def distinct: Array[A]

    Selects all the elements of this array ignoring the duplicates.

    Selects all the elements of this array ignoring the duplicates.

    returns

      a new array consisting of all the elements of this array without duplicates.

30.  def distinctBy[B](f: (A) => B): Array[A]

    Selects all the elements of this array ignoring the duplicates as determined by `==` after applying the transforming function `f`.

    Selects all the elements of this array ignoring the duplicates as determined by `==` after applying the transforming function `f`.

    B

      the type of the elements after being transformed by `f`

    f

      The transforming function whose result is used to determine the uniqueness of each element

    returns

      a new array consisting of all the elements of this array without duplicates.

31.  def drop(n: Int): Array[A]

    The rest of the array without its `n` first elements.

32.  def dropRight(n: Int): Array[A]

    The rest of the array without its `n` last elements.

33.  def dropWhile(p: (A) => Boolean): Array[A]

    Drops longest prefix of elements that satisfy a predicate.

    Drops longest prefix of elements that satisfy a predicate.

    p

      The predicate used to test elements.

    returns

      the longest suffix of this array whose first element does not satisfy the predicate `p`.

34.  def endsWith[B >: A](that: Iterable[B]): Boolean

    Tests whether this array ends with the given sequence.

    Tests whether this array ends with the given sequence.

    that

      the sequence to test

    returns

      `true` if this array has `that` as a suffix, `false` otherwise.

35.  def endsWith[B >: A](that: Array[B]): Boolean

    Tests whether this array ends with the given array.

    Tests whether this array ends with the given array.

    that

      the array to test

    returns

      `true` if this array has `that` as a suffix, `false` otherwise.

36.  def ensuring(cond: (ArrayOps[A]) => Boolean, msg: => Any): ArrayOps[A]
    Implicit
      This member is added by an implicit conversion from ArrayOps[A] toEnsuring[ArrayOps[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
37.  def ensuring(cond: (ArrayOps[A]) => Boolean): ArrayOps[A]
    Implicit
      This member is added by an implicit conversion from ArrayOps[A] toEnsuring[ArrayOps[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
38.  def ensuring(cond: Boolean, msg: => Any): ArrayOps[A]
    Implicit
      This member is added by an implicit conversion from ArrayOps[A] toEnsuring[ArrayOps[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
39.  def ensuring(cond: Boolean): ArrayOps[A]
    Implicit
      This member is added by an implicit conversion from ArrayOps[A] toEnsuring[ArrayOps[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
40.  def exists(p: (A) => Boolean): Boolean

    Tests whether a predicate holds for at least one element of this array.

    Tests whether a predicate holds for at least one element of this array.

    p

      the predicate used to test elements.

    returns

      `true` if the given predicate `p` is satisfied by at least one element of this array, otherwise `false`

41.  def filter(p: (A) => Boolean): Array[A]

    Selects all elements of this array which satisfy a predicate.

    Selects all elements of this array which satisfy a predicate.

    p

      the predicate used to test elements.

    returns

      a new array consisting of all elements of this array that satisfy the given predicate `p`.

42.  def filterNot(p: (A) => Boolean): Array[A]

    Selects all elements of this array which do not satisfy a predicate.

    Selects all elements of this array which do not satisfy a predicate.

    p

      the predicate used to test elements.

    returns

      a new array consisting of all elements of this array that do not satisfy the given predicate `p`.

43.  def find(p: (A) => Boolean): Option[A]

    Finds the first element of the array satisfying a predicate, if any.

    Finds the first element of the array satisfying a predicate, if any.

    p

      the predicate used to test elements.

    returns

      an option value containing the first element in the array that satisfies `p`, or `None` if none exists.

44.  def flatMap[BS, B](f: (A) => BS)(implicit asIterable: (BS) => Iterable[B], m: ClassTag[B]): Array[B]
45.  def flatMap[B](f: (A) => IterableOnce[B])(implicit arg0: ClassTag[B]): Array[B]

    Builds a new array by applying a function to all elements of this array and using the elements of the resulting collections.

    Builds a new array by applying a function to all elements of this array and using the elements of the resulting collections.

    B

      the element type of the returned array.

    f

      the function to apply to each element.

    returns

      a new array resulting from applying the given collection-valued function `f` to each element of this array and concatenating the results.

46.  def flatten[B](implicit asIterable: (A) => IterableOnce[B], m: ClassTag[B]): Array[B]

    Flattens a two-dimensional array by concatenating all its rows into a single array.

    Flattens a two-dimensional array by concatenating all its rows into a single array.

    B

      Type of row elements.

    asIterable

      A function that converts elements of this array to rows - Iterables of type `B`.

    returns

      An array obtained by concatenating rows of this array.

47.  def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1

    Alias for foldLeft.

    Alias for foldLeft.

    The type parameter is more restrictive than for `foldLeft` to be consistent with IterableOnceOps.fold.

    A1

      The type parameter for the binary operator, a supertype of `A`.

    z

      An initial value.

    op

      A binary operator.

    returns

      The result of applying `op` to `z` and all elements of this array, going left to right. Returns `z` if this string is empty.

48.  def foldLeft[B](z: B)(op: (B, A) => B): B

    Applies the given binary operator `op` to the given initial value `z` and all elements of this array, going left to right.

    Applies the given binary operator `op` to the given initial value `z` and all elements of this array, going left to right. Returns the initial value if this array is empty.

    If `x1`, `x2`, ..., `xn` are the elements of this array, the result is `op( op( ... op( op(z, x1), x2) ... ), xn)`.

    B

      The result type of the binary operator.

    z

      An initial value.

    op

      A binary operator.

    returns

      The result of applying `op` to `z` and all elements of this array, going left to right. Returns `z` if this array is empty.

49.  def foldRight[B](z: B)(op: (A, B) => B): B

    Applies the given binary operator `op` to all elements of this array and the given initial value `z`, going right to left.

    Applies the given binary operator `op` to all elements of this array and the given initial value `z`, going right to left. Returns the initial value if this array is empty.

    If `x1`, `x2`, ..., `xn` are the elements of this array, the result is `op(x1, op(x2, op( ... op(xn, z) ... )))`.

    B

      The result type of the binary operator.

    z

      An initial value.

    op

      A binary operator.

    returns

      The result of applying `op` to all elements of this array and `z`, going right to left. Returns `z` if this array is empty.

50.  def forall(p: (A) => Boolean): Boolean

    Tests whether a predicate holds for all elements of this array.

    Tests whether a predicate holds for all elements of this array.

    p

      the predicate used to test elements.

    returns

      `true` if this array is empty or the given predicate `p` holds for all elements of this array, otherwise `false`.

51.  def foreach[U](f: (A) => U): Unit

    Apply `f` to each element for its side effects.

    Apply `f` to each element for its side effects. Note: [U] parameter needed to help scalac's type inference.

52.  def getClass(): Class[_ <: AnyVal]

    Returns the runtime class representation of the object.

    Returns the runtime class representation of the object.

    returns

      a class object corresponding to the runtime type of the receiver.

    Definition Classes
      AnyVal → Any
53.  def groupBy[K](f: (A) => K): immutable.Map[K, Array[A]]

    Partitions this array into a map of arrays according to some discriminator function.

    Partitions this array into a map of arrays according to some discriminator function.

    K

      the type of keys returned by the discriminator function.

    f

      the discriminator function.

    returns

      A map from keys to arrays such that the following invariant holds:

          (xs groupBy f)(k) = xs filter (x => f(x) == k)

      That is, every key `k` is bound to an array of those elements `x` for which `f(x)` equals `k`.

54.  def groupMap[K, B](key: (A) => K)(f: (A) => B)(implicit arg0: ClassTag[B]): immutable.Map[K, Array[B]]

    Partitions this array into a map of arrays according to a discriminator function `key`.

    Partitions this array into a map of arrays according to a discriminator function `key`. Each element in a group is transformed into a value of type `B` using the `value` function.

    It is equivalent to `groupBy(key).mapValues(_.map(f))`, but more efficient.

        case class User(name: String, age: Int)

        def namesByAge(users: Array[User]): Map[Int, Array[String]] =
          users.groupMap(_.age)(_.name)

    K

      the type of keys returned by the discriminator function

    B

      the type of values returned by the transformation function

    key

      the discriminator function

    f

      the element transformation function

55.  def grouped(size: Int): Iterator[Array[A]]

    Partitions elements in fixed size arrays.

    Partitions elements in fixed size arrays.

    size

      the number of elements per group

    returns

      An iterator producing arrays of size `size`, except the last will be less than size `size` if the elements don't divide evenly.

    See also

      scala.collection.Iterator, method `grouped`

56.  def head: A

    Selects the first element of this array.

    Selects the first element of this array.

    returns

      the first element of this array.

    Exceptions thrown

      `NoSuchElementException` if the array is empty.

57.  def headOption: Option[A]

    Optionally selects the first element.

    Optionally selects the first element.

    returns

      the first element of this array if it is nonempty, `None` if it is empty.

58.  def indexOf(elem: A, from: Int = 0): Int

    Finds index of first occurrence of some value in this array after or at some start index.

    Finds index of first occurrence of some value in this array after or at some start index.

    elem

      the element value to search for.

    from

      the start index

    returns

      the index `>= from` of the first element of this array that is equal (as determined by `==`) to `elem`, or `-1`, if none exists.

59.  def indexWhere(p: (A) => Boolean, from: Int = 0): Int

    Finds index of the first element satisfying some predicate after or at some start index.

    Finds index of the first element satisfying some predicate after or at some start index.

    p

      the predicate used to test elements.

    from

      the start index

    returns

      the index `>= from` of the first element of this array that satisfies the predicate `p`, or `-1`, if none exists.

60.  def indices: immutable.Range

    Produces the range of all indices of this sequence.

    Produces the range of all indices of this sequence.

    returns

      a `Range` value from `0` to one less than the length of this array.

61.  def init: Array[A]

    The initial part of the array without its last element.

62.  def inits: Iterator[Array[A]]

    Iterates over the inits of this array.

    Iterates over the inits of this array. The first value will be this array and the final one will be an empty array, with the intervening values the results of successive applications of `init`.

    returns

      an iterator over all the inits of this array

63.  def intersect[B >: A](that: Seq[B]): Array[A]

    Computes the multiset intersection between this array and another sequence.

    Computes the multiset intersection between this array and another sequence.

    that

      the sequence of elements to intersect with.

    returns

      a new array which contains all elements of this array which also appear in `that`. If an element value `x` appears n times in `that`, then the first n occurrences of `x` will be retained in the result, but any following occurrences will be omitted.

64.  def isEmpty: Boolean

    Tests whether the array is empty.

    Tests whether the array is empty.

    returns

      `true` if the array contains no elements, `false` otherwise.

    Annotations
      @inline()
65.  final def isInstanceOf[T0]: Boolean

    Test whether the dynamic type of the receiver object has the same erasure as `T0`.

    Test whether the dynamic type of the receiver object has the same erasure as `T0`.

    Depending on what `T0` is, the test is done in one of the below ways:

    - `T0` is a non-parameterized class type, e.g. `BigDecimal`: this method returns `true` if the value of the receiver object is a `BigDecimal` or a subtype of `BigDecimal`.
    - `T0` is a parameterized class type, e.g. `List[Int]`: this method returns `true` if the value of the receiver object is some `List[X]` for any `X`. For example, `List(1, 2, 3).isInstanceOf[List[String]]` will return true.
    - `T0` is some singleton type `x.type` or literal `x`: this method returns `this.eq(x)`. For example, `x.isInstanceOf[1]` is equivalent to `x.eq(1)`
    - `T0` is an intersection `X with Y` or `X & Y: this method is equivalent to` x.isInstanceOf[X] && x.isInstanceOf[Y]``
    - `T0` is a union `X | Y`: this method is equivalent to `x.isInstanceOf[X] || x.isInstanceOf[Y]`
    - `T0` is a type parameter or an abstract type member: this method is equivalent to `isInstanceOf[U]` where `U` is `T0`'s upper bound, `Any` if `T0` is unbounded. For example, `x.isInstanceOf[A]` where `A` is an unbounded type parameter will return true for any value of `x`.

    This is exactly equivalent to the type pattern `_: T0`

    returns

      `true` if the receiver object is an instance of erasure of type `T0`; `false` otherwise.

    Definition Classes
      Any
    Note

      due to the unexpectedness of `List(1, 2, 3).isInstanceOf[List[String]]` returning true and `x.isInstanceOf[A]` where `A` is a type parameter or abstract member returning true, these forms issue a warning.

66.  def iterator: Iterator[A]
67.  def knownSize: Int

    The size of this array.

    The size of this array.

    returns

      the number of elements in this array.

    Annotations
      @inline()
68.  def last: A

    Selects the last element.

    Selects the last element.

    returns

      The last element of this array.

    Exceptions thrown

      `NoSuchElementException` If the array is empty.

69.  def lastIndexOf(elem: A, end: Int = xs.length - 1): Int

    Finds index of last occurrence of some value in this array before or at a given end index.

    Finds index of last occurrence of some value in this array before or at a given end index.

    elem

      the element value to search for.

    end

      the end index.

    returns

      the index `<= end` of the last element of this array that is equal (as determined by `==`) to `elem`, or `-1`, if none exists.

70.  def lastIndexWhere(p: (A) => Boolean, end: Int = xs.length - 1): Int

    Finds index of last element satisfying some predicate before or at given end index.

    Finds index of last element satisfying some predicate before or at given end index.

    p

      the predicate used to test elements.

    returns

      the index `<= end` of the last element of this array that satisfies the predicate `p`, or `-1`, if none exists.

71.  def lastOption: Option[A]

    Optionally selects the last element.

    Optionally selects the last element.

    returns

      the last element of this array$ if it is nonempty, `None` if it is empty.

72.  def lazyZip[B](that: Iterable[B]): LazyZip2[A, B, Array[A]]

    Analogous to `zip` except that the elements in each collection are not consumed until a strict operation is invoked on the returned `LazyZip2` decorator.

    Analogous to `zip` except that the elements in each collection are not consumed until a strict operation is invoked on the returned `LazyZip2` decorator.

    Calls to `lazyZip` can be chained to support higher arities (up to 4) without incurring the expense of constructing and deconstructing intermediary tuples.

        val xs = List(1, 2, 3)
        val res = (xs lazyZip xs lazyZip xs lazyZip xs).map((a, b, c, d) => a + b + c + d)
        // res == List(4, 8, 12)

    B

      the type of the second element in each eventual pair

    that

      the iterable providing the second element of each eventual pair

    returns

      a decorator `LazyZip2` that allows strict operations to be performed on the lazily evaluated pairs or chained calls to `lazyZip`. Implicit conversion to `Iterable[(A, B)]` is also supported.

73.  def lengthCompare(len: Int): Int

    Compares the length of this array to a test value.

    Compares the length of this array to a test value.

    len

      the test value that gets compared with the length.

    returns

      A value `x` where

          x <  0       if this.length <  len
          x == 0       if this.length == len
          x >  0       if this.length >  len

74.  def lengthIs: Int

    Method mirroring SeqOps.lengthIs for consistency, except it returns an `Int` because `length` is known and comparison is constant-time.

    Method mirroring SeqOps.lengthIs for consistency, except it returns an `Int` because `length` is known and comparison is constant-time.

    These operations are equivalent to `lengthCompare(Int)`, and allow the following more readable usages:

        this.lengthIs < len     // this.lengthCompare(len) < 0
        this.lengthIs <= len    // this.lengthCompare(len) <= 0
        this.lengthIs == len    // this.lengthCompare(len) == 0
        this.lengthIs != len    // this.lengthCompare(len) != 0
        this.lengthIs >= len    // this.lengthCompare(len) >= 0
        this.lengthIs > len     // this.lengthCompare(len) > 0

75.  def map[B](f: (A) => B)(implicit ct: ClassTag[B]): Array[B]

    Builds a new array by applying a function to all elements of this array.

    Builds a new array by applying a function to all elements of this array.

    B

      the element type of the returned array.

    f

      the function to apply to each element.

    returns

      a new array resulting from applying the given function `f` to each element of this array and collecting the results.

76.  def mapInPlace(f: (A) => A): Array[A]
77.  def nonEmpty: Boolean

    Tests whether the array is not empty.

    Tests whether the array is not empty.

    returns

      `true` if the array contains at least one element, `false` otherwise.

    Annotations
      @inline()
78.  def padTo[B >: A](len: Int, elem: B)(implicit arg0: ClassTag[B]): Array[B]

    A copy of this array with an element value appended until a given target length is reached.

    A copy of this array with an element value appended until a given target length is reached.

    B

      the element type of the returned array.

    len

      the target length

    elem

      the padding value

    returns

      a new array consisting of all elements of this array followed by the minimal number of occurrences of `elem` so that the resulting collection has a length of at least `len`.

79.  def partition(p: (A) => Boolean): (Array[A], Array[A])

    A pair of, first, all elements that satisfy predicate `p` and, second, all elements that do not.

80.  def partitionMap[A1, A2](f: (A) => Either[A1, A2])(implicit arg0: ClassTag[A1], arg1: ClassTag[A2]): (Array[A1], Array[A2])

    Applies a function `f` to each element of the array and returns a pair of arrays: the first one made of those values returned by `f` that were wrapped in scala.util.Left, and the second one made of those wrapped in scala.util.Right.

    Applies a function `f` to each element of the array and returns a pair of arrays: the first one made of those values returned by `f` that were wrapped in scala.util.Left, and the second one made of those wrapped in scala.util.Right.

    Example:

        val xs = Array(1, "one", 2, "two", 3, "three") partitionMap {
         case i: Int => Left(i)
         case s: String => Right(s)
        }
        // xs == (Array(1, 2, 3),
        //        Array(one, two, three))

    A1

      the element type of the first resulting collection

    A2

      the element type of the second resulting collection

    f

      the 'split function' mapping the elements of this array to an scala.util.Either

    returns

      a pair of arrays: the first one made of those values returned by `f` that were wrapped in scala.util.Left, and the second one made of those wrapped in scala.util.Right.

81.  def patch[B >: A](from: Int, other: IterableOnce[B], replaced: Int)(implicit arg0: ClassTag[B]): Array[B]

    Returns a copy of this array with patched values.

    Returns a copy of this array with patched values. Patching at negative indices is the same as patching starting at 0. Patching at indices at or larger than the length of the original array appends the patch to the end. If more values are replaced than actually exist, the excess is ignored.

    from

      The start index from which to patch

    other

      The patch values

    replaced

      The number of values in the original array that are replaced by the patch.

82.  def permutations: Iterator[Array[A]]

    Iterates over distinct permutations of elements.

    Iterates over distinct permutations of elements.

    returns

      An Iterator which traverses the distinct permutations of this array.

    Example:

    1.     Array('a', 'b', 'b').permutations.map(runtime.ScalaRunTime.stringOf).foreach(println)
           // Array(a, b, b)
           // Array(b, a, b)
           // Array(b, b, a)

83.  def prepended[B >: A](x: B)(implicit arg0: ClassTag[B]): Array[B]

    A copy of this array with an element prepended.

84.  def prependedAll[B >: A](prefix: Array[_ <: B])(implicit arg0: ClassTag[B]): Array[B]

    A copy of this array with all elements of an array prepended.

85.  def prependedAll[B >: A](prefix: IterableOnce[B])(implicit arg0: ClassTag[B]): Array[B]

    A copy of this array with all elements of a collection prepended.

86.  def reverse: Array[A]

    Returns a new array with the elements in reversed order.

    Returns a new array with the elements in reversed order.

    Annotations
      @inline()
87.  def reverseIterator: Iterator[A]

    An iterator yielding elements in reversed order.

    An iterator yielding elements in reversed order.

    Note: `xs.reverseIterator` is the same as `xs.reverse.iterator` but implemented more efficiently.

    returns

      an iterator yielding the elements of this array in reversed order

88.  def scan[B >: A](z: B)(op: (B, B) => B)(implicit arg0: ClassTag[B]): Array[B]

    Computes a prefix scan of the elements of the array.

    Computes a prefix scan of the elements of the array.

    Note: The neutral element `z` may be applied more than once.

    B

      element type of the resulting array

    z

      neutral element for the operator `op`

    op

      the associative operator for the scan

    returns

      a new array containing the prefix scan of the elements in this array

89.  def scanLeft[B](z: B)(op: (B, A) => B)(implicit arg0: ClassTag[B]): Array[B]

    Produces an array containing cumulative results of applying the binary operator going left to right.

    Produces an array containing cumulative results of applying the binary operator going left to right.

    B

      the result type of the binary operator.

    z

      the start value.

    op

      the binary operator.

    returns

      array with intermediate values. Example:

          Array(1, 2, 3, 4).scanLeft(0)(_ + _) == Array(0, 1, 3, 6, 10)

90.  def scanRight[B](z: B)(op: (A, B) => B)(implicit arg0: ClassTag[B]): Array[B]

    Produces an array containing cumulative results of applying the binary operator going right to left.

    Produces an array containing cumulative results of applying the binary operator going right to left.

    B

      the result type of the binary operator.

    z

      the start value.

    op

      the binary operator.

    returns

      array with intermediate values. Example:

          Array(4, 3, 2, 1).scanRight(0)(_ + _) == Array(10, 6, 3, 1, 0)

91.  def size: Int

    The size of this array.

    The size of this array.

    returns

      the number of elements in this array.

    Annotations
      @inline()
92.  def sizeCompare(otherSize: Int): Int

    Compares the size of this array to a test value.

    Compares the size of this array to a test value.

    otherSize

      the test value that gets compared with the size.

    returns

      A value `x` where

          x <  0       if this.size <  otherSize
          x == 0       if this.size == otherSize
          x >  0       if this.size >  otherSize

93.  def sizeIs: Int

    Method mirroring SeqOps.sizeIs for consistency, except it returns an `Int` because `size` is known and comparison is constant-time.

    Method mirroring SeqOps.sizeIs for consistency, except it returns an `Int` because `size` is known and comparison is constant-time.

    These operations are equivalent to `sizeCompare(Int)`, and allow the following more readable usages:

        this.sizeIs < size     // this.sizeCompare(size) < 0
        this.sizeIs <= size    // this.sizeCompare(size) <= 0
        this.sizeIs == size    // this.sizeCompare(size) == 0
        this.sizeIs != size    // this.sizeCompare(size) != 0
        this.sizeIs >= size    // this.sizeCompare(size) >= 0
        this.sizeIs > size     // this.sizeCompare(size) > 0

94.  def slice(from: Int, until: Int): Array[A]

    Selects an interval of elements.

    Selects an interval of elements. The returned array is made up of all elements `x` which satisfy the invariant:

        from <= indexOf(x) < until

    from

      the lowest index to include from this array.

    until

      the lowest index to EXCLUDE from this array.

    returns

      an array containing the elements greater than or equal to index `from` extending up to (but not including) index `until` of this array.

95.  def sliding(size: Int, step: Int = 1): Iterator[Array[A]]

    Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.)

    Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.)

    size

      the number of elements per group

    step

      the distance between the first elements of successive groups

    returns

      An iterator producing arrays of size `size`, except the last element (which may be the only element) will be truncated if there are fewer than `size` elements remaining to be grouped.

    See also

      scala.collection.Iterator, method `sliding`

96.  def sortBy[B](f: (A) => B)(implicit ord: math.Ordering[B]): Array[A]

    Sorts this array according to the Ordering which results from transforming an implicitly given Ordering with a transformation function.

    Sorts this array according to the Ordering which results from transforming an implicitly given Ordering with a transformation function.

    B

      the target type of the transformation `f`, and the type where the ordering `ord` is defined.

    f

      the transformation function mapping elements to some other domain `B`.

    ord

      the ordering assumed on domain `B`.

    returns

      an array consisting of the elements of this array sorted according to the ordering where `x < y` if `ord.lt(f(x), f(y))`.

    See also

      scala.math.Ordering

97.  def sortWith(lt: (A, A) => Boolean): Array[A]

    Sorts this array according to a comparison function.

    Sorts this array according to a comparison function.

    The sort is stable. That is, elements that are equal (as determined by `lt`) appear in the same order in the sorted sequence as in the original.

    lt

      the comparison function which tests whether its first argument precedes its second argument in the desired ordering.

    returns

      an array consisting of the elements of this array sorted according to the comparison function `lt`.

98.  def sorted[B >: A](implicit ord: math.Ordering[B]): Array[A]

    Sorts this array according to an Ordering.

    Sorts this array according to an Ordering.

    The sort is stable. That is, elements that are equal (as determined by `lt`) appear in the same order in the sorted sequence as in the original.

    ord

      the ordering to be used to compare elements.

    returns

      an array consisting of the elements of this array sorted according to the ordering `ord`.

    See also

      scala.math.Ordering

99.  def span(p: (A) => Boolean): (Array[A], Array[A])

    Splits this array into a prefix/suffix pair according to a predicate.

    Splits this array into a prefix/suffix pair according to a predicate.

    Note: `c span p` is equivalent to (but more efficient than) `(c takeWhile p, c dropWhile p)`, provided the evaluation of the predicate `p` does not cause any side-effects.

    p

      the test predicate

    returns

      a pair consisting of the longest prefix of this array whose elements all satisfy `p`, and the rest of this array.

100.  def splitAt(n: Int): (Array[A], Array[A])

     Splits this array into two at a given position.

     Splits this array into two at a given position. Note: `c splitAt n` is equivalent to `(c take n, c drop n)`.

     n

       the position at which to split.

     returns

       a pair of arrays consisting of the first `n` elements of this array, and the other elements.

101.  def startsWith[B >: A](that: IterableOnce[B], offset: Int = 0): Boolean

     Tests whether this array contains the given sequence at a given index.

     Tests whether this array contains the given sequence at a given index.

     that

       the sequence to test

     offset

       the index where the sequence is searched.

     returns

       `true` if the sequence `that` is contained in this array at index `offset`, otherwise `false`.

102.  def startsWith[B >: A](that: Array[B], offset: Int): Boolean

     Tests whether this array contains the given array at a given index.

     Tests whether this array contains the given array at a given index.

     that

       the array to test

     offset

       the index where the array is searched.

     returns

       `true` if the array `that` is contained in this array at index `offset`, otherwise `false`.

103.  def startsWith[B >: A](that: Array[B]): Boolean

     Tests whether this array starts with the given array.

     Tests whether this array starts with the given array.

     Annotations
       @inline()
104.  def stepper[S <: Stepper[_]](implicit shape: StepperShape[A, S]): S with EfficientSplit
105.  def tail: Array[A]

     The rest of the array without its first element.

106.  def tails: Iterator[Array[A]]

     Iterates over the tails of this array.

     Iterates over the tails of this array. The first value will be this array and the final one will be an empty array, with the intervening values the results of successive applications of `tail`.

     returns

       an iterator over all the tails of this array

107.  def take(n: Int): Array[A]

     An array containing the first `n` elements of this array.

108.  def takeRight(n: Int): Array[A]

     An array containing the last `n` elements of this array.

109.  def takeWhile(p: (A) => Boolean): Array[A]

     Takes longest prefix of elements that satisfy a predicate.

     Takes longest prefix of elements that satisfy a predicate.

     p

       The predicate used to test elements.

     returns

       the longest prefix of this array whose elements all satisfy the predicate `p`.

110.  def toArray[B >: A](implicit arg0: ClassTag[B]): Array[B]

     Create a copy of this array with the specified element type.

111.  def toIndexedSeq: immutable.IndexedSeq[A]
112.  final def toSeq: immutable.Seq[A]
     Annotations
       @inline()
113.  def toString(): String

     Returns a string representation of the object.

     Returns a string representation of the object.

     The default representation is platform dependent.

     returns

       a string representation of the object.

     Definition Classes
       Any
114.  def transpose[B](implicit asArray: (A) => Array[B]): Array[Array[B]]

     Transposes a two dimensional array.

     Transposes a two dimensional array.

     B

       Type of row elements.

     asArray

       A function that converts elements of this array to rows - arrays of type `B`.

     returns

       An array obtained by replacing elements of this arrays with rows the represent.

115.  def unzip[A1, A2](implicit asPair: (A) => (A1, A2), ct1: ClassTag[A1], ct2: ClassTag[A2]): (Array[A1], Array[A2])

     Converts an array of pairs into an array of first elements and an array of second elements.

     Converts an array of pairs into an array of first elements and an array of second elements.

     A1

       the type of the first half of the element pairs

     A2

       the type of the second half of the element pairs

     asPair

       an implicit conversion which asserts that the element type of this Array is a pair.

     ct1

       a class tag for `A1` type parameter that is required to create an instance of `Array[A1]`

     ct2

       a class tag for `A2` type parameter that is required to create an instance of `Array[A2]`

     returns

       a pair of Arrays, containing, respectively, the first and second half of each element pair of this Array.

116.  def unzip3[A1, A2, A3](implicit asTriple: (A) => (A1, A2, A3), ct1: ClassTag[A1], ct2: ClassTag[A2], ct3: ClassTag[A3]): (Array[A1], Array[A2], Array[A3])

     Converts an array of triples into three arrays, one containing the elements from each position of the triple.

     Converts an array of triples into three arrays, one containing the elements from each position of the triple.

     A1

       the type of the first of three elements in the triple

     A2

       the type of the second of three elements in the triple

     A3

       the type of the third of three elements in the triple

     asTriple

       an implicit conversion which asserts that the element type of this Array is a triple.

     ct1

       a class tag for T1 type parameter that is required to create an instance of Array[T1]

     ct2

       a class tag for T2 type parameter that is required to create an instance of Array[T2]

     ct3

       a class tag for T3 type parameter that is required to create an instance of Array[T3]

     returns

       a triple of Arrays, containing, respectively, the first, second, and third elements from each element triple of this Array.

117.  def updated[B >: A](index: Int, elem: B)(implicit arg0: ClassTag[B]): Array[B]

     A copy of this array with one single replaced element.

     A copy of this array with one single replaced element.

     index

       the position of the replacement

     elem

       the replacing element

     returns

       a new array which is a copy of this array with the element at position `index` replaced by `elem`.

     Exceptions thrown

       `IndexOutOfBoundsException` if `index` does not satisfy `0 <= index < length`.

118.  def view: IndexedSeqView[A]
     Annotations
       @inline()
119.  def withFilter(p: (A) => Boolean): ArrayOps.WithFilter[A]

     Creates a non-strict filter of this array.

     Creates a non-strict filter of this array.

     Note: the difference between `c filter p` and `c withFilter p` is that the former creates a new array, whereas the latter only restricts the domain of subsequent `map`, `flatMap`, `foreach`, and `withFilter` operations.

     p

       the predicate used to test elements.

     returns

       an object of class `ArrayOps.WithFilter`, which supports `map`, `flatMap`, `foreach`, and `withFilter` operations. All these operations apply to those elements of this array which satisfy the predicate `p`.

120.  def zip[B](that: IterableOnce[B]): Array[(A, B)]

     Returns an array formed from this array and another iterable collection by combining corresponding elements in pairs.

     Returns an array formed from this array and another iterable collection by combining corresponding elements in pairs. If one of the two collections is longer than the other, its remaining elements are ignored.

     B

       the type of the second half of the returned pairs

     that

       The iterable providing the second half of each result pair

     returns

       a new array containing pairs consisting of corresponding elements of this array and `that`. The length of the returned array is the minimum of the lengths of this array and `that`.

121.  def zipAll[A1 >: A, B](that: Iterable[B], thisElem: A1, thatElem: B): Array[(A1, B)]

     Returns an array formed from this array and another iterable collection by combining corresponding elements in pairs.

     Returns an array formed from this array and another iterable collection by combining corresponding elements in pairs. If one of the two collections is shorter than the other, placeholder elements are used to extend the shorter collection to the length of the longer.

     that

       the iterable providing the second half of each result pair

     thisElem

       the element to be used to fill up the result if this array is shorter than `that`.

     thatElem

       the element to be used to fill up the result if `that` is shorter than this array.

     returns

       a new array containing pairs consisting of corresponding elements of this array and `that`. The length of the returned array is the maximum of the lengths of this array and `that`. If this array is shorter than `that`, `thisElem` values are used to pad the result. If `that` is shorter than this array, `thatElem` values are used to pad the result.

122.  def zipWithIndex: Array[(A, Int)]

     Zips this array with its indices.

     Zips this array with its indices.

     returns

       A new array containing pairs consisting of all elements of this array paired with their index. Indices start at `0`.

### Deprecated Value Members

1.  def formatted(fmtstr: String): String

   Returns string formatted according to given `format` string.

   Returns string formatted according to given `format` string. Format strings are as for `String.format` (@see java.lang.String.format).

   Implicit
     This member is added by an implicit conversion from ArrayOps[A] toStringFormat[ArrayOps[A]] performed by method StringFormat in scala.Predef.
   Definition Classes
     StringFormat
   Annotations
     @deprecated @inline()
   Deprecated

     (Since version 2.12.16) Use `formatString.format(value)` instead of `value.formatted(formatString)`, or use the `f""` string interpolator. In Java 15 and later, `formatted` resolves to the new method in String which has reversed parameters.

2.  def →[B](y: B): (ArrayOps[A], B)
   Implicit
     This member is added by an implicit conversion from ArrayOps[A] toArrowAssoc[ArrayOps[A]] performed by method ArrowAssoc in scala.Predef.
   Definition Classes
     ArrowAssoc
   Annotations
     @deprecated
   Deprecated

     (Since version 2.13.0) Use `->` instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

### Inherited from AnyVal

### Inherited from Any

### Inherited by implicit conversion any2stringadd fromArrayOps[A] to any2stringadd[ArrayOps[A]]

### Inherited by implicit conversion StringFormat fromArrayOps[A] to StringFormat[ArrayOps[A]]

### Inherited by implicit conversion Ensuring fromArrayOps[A] to Ensuring[ArrayOps[A]]

### Inherited by implicit conversion ArrowAssoc fromArrayOps[A] to ArrowAssoc[ArrayOps[A]]

### Ungrouped