Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:29:58+00:00 2026-05-31T10:29:58+00:00

for (i <- Array.apply(1 to 4)) print(i); Range(1, 2, 3, 4) Range(1, 10) //res0:

  • 0
for (i <- Array.apply(1 to 4))
      print(i);

Range(1, 2, 3, 4)

Range(1, 10)

//res0: scala.collection.immutable.Range = Range(1, 2, 3, 4, 5, 6, 7, 8, 9)

So why does val range = Range(1, 2, 3, 4) give error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:29:59+00:00Added an answer on May 31, 2026 at 10:29 am

    A Range is a special kind of collection that is restricted in what it can represent in order to efficiently perform its operations. It is only able to represent a sequence of numbers with a fixed step in between elements. As such, it only needs to be told about the start, end, and step size in order to be constructed. An Array on the other can hold arbitrary values, so its constructor must be told explicitly what those values are.

    The definition of Range.apply is that it takes either:

    • two arguments: a start and end for a range, or
    • three arguments: a start, end, and step size for the range.

    Here are the definitions of apply from scala.collection.immutable.Range:

    /** Make a range from `start` until `end` (exclusive) with given step value.
     * @note step != 0
     */
    def apply(start: Int, end: Int, step: Int): Range = new Range(start, end, step)
    
    /** Make an range from `start` to `end` inclusive with step value 1.
     */
    def apply(start: Int, end: Int): Range = new Range(start, end, 1) 
    

    Constrast this with the apply for scala.Array, which accepts a variable-length argument T*:

    /** Creates an array with given elements.
     *
     *  @param xs the elements to put in the array
     *  @return an array containing all elements from xs.
     */
    def apply[T: ClassManifest](xs: T*): Array[T] = {
      val array = new Array[T](xs.length)
      var i = 0
      for (x <- xs.iterator) { array(i) = x; i += 1 }
      array
    }
    

    If your goal is to have an Array of the numbers 1 to 4, try this:

    (1 to 4).toArray
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I'm trying to do is take an array of service names and apply
consider the following code: class MyClass(object): def __init__(self): self.data_a = np.array(range(100)) self.data_b = np.array(range(100,200))
Example: $arr = array( 'apple' => 'sweet', 'grapefruit' => 'bitter', 'pear' => 'tasty', 'banana'
I have an array apple color: red price: 2 orange color: orange price: 3
So let's say I have this array: $requiredFruit= @(apple,pear,nectarine,grape) And I'm given a second
I have an array $data fruit => apple, seat => sofa, etc. I want
Basic array question: $string = The quick brown cat; $check1 = apple; $check2 =
I am looping through an array of strings, such as (1/12/1992 apple truck 12/10/10
I have a simple simulated array with two elements: bowl["fruit"] = "apple"; bowl["nuts"] =
Array 1 | Array 2 ================= 1 | 2 2 | 3 3 |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.