Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

The Array Collection

Sumit Rawal answered on May 23, 2023 Popularity 4/10 Helpfulness 1/10

Contents


More Related Answers

  • collect as arr java 8
  • Access Array Elements Java
  • javascript list of array methods
  • The java.util.Arrays class
  • java array list example
  • java array object
  • js collection
  • what are the parts of an array called
  • Array pocket in java
  • system.collections.arraylist

  • The Array Collection

    0

    Introduction

    Creating and Populating an Array

    With Sequence Methods

    With new

    A Handful of Methods

    Using range

    Using fill

    Using toArray

    Accessing Elements of an Array

    Length of an Array

    Introduction

    Arrays in Scala are collections which come under the sequence class. They are a mutable collection, hence, when elements in an array are modified, the original array is updated. However, it is important to mention here that in one-way arrays are also immutable as the size of the array cannot change.

    Scala arrays are represented as Java arrays. So, the Scala array Array[Int], is represented as the Java array int[] and the Scala array Array[String] is represented as the Java array string[], and so on. That being said, Scala arrays have a lot more to offer and in the next two lessons, we will see exactly how that is.

    Creating and Populating an Array

    While there are multiple ways of populating and defining an array in Scala, the basic syntax of creating an array from scratch remains the same with the keyword Array followed by () in which you mention the elements you want to populate your array with.


    The Array method is creating an Array object.

    Let’s look at a simple example where we want to create and populate an array with the first ten positive integers. 

    Popularity 4/10 Helpfulness 1/10 Language scala
    Source: Grepper
    Tags: scala
    Link to this answer
    Share Copy Link
    Contributed on May 23 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.