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 8661335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:28:25+00:00 2026-06-12T16:28:25+00:00

Lists are immutable in Scala, so I’m trying to figure out how I can

  • 0

Lists are immutable in Scala, so I’m trying to figure out how I can “remove” – really, create a new collection – that element and then close the gap created in the list. This sounds to me like it would be a great place to use map, but I don’t know how to get started in this instance.

Courses is a list of strings. I need this loop because I actually have several lists that I will need to remove the element at that index from (I’m using multiple lists to store data associated across lists, and I’m doing this by simply ensuring that the indices will always correspond across lists).

  for (i <- 0 until courses.length){
    if (input == courses(i) {
    //I need a map call on each list here to remove that element
    //this element is not guaranteed to be at the front or the end of the list
    }
  }
}

Let me add some detail to the problem. I have four lists that are associated with each other by index; one list stores the course names, one stores the time the class begins in a simple int format (ie 130), one stores either “am” or “pm”, and one stores the days of the classes by int (so “MWF” evals to 1, “TR” evals to 2, etc). I don’t know if having multiple this is the best or the “right” way to solve this problem, but these are all the tools I have (first-year comp sci student that hasn’t programmed seriously since I was 16). I’m writing a function to remove the corresponding element from each lists, and all I know is that 1) the indices correspond and 2) the user inputs the course name. How can I remove the corresponding element from each list using filterNot? I don’t think I know enough about each list to use higher order functions on them.

  • 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-06-12T16:28:26+00:00Added an answer on June 12, 2026 at 4:28 pm

    This is the use case of filter:

    scala> List(1,2,3,4,5)
    res0: List[Int] = List(1, 2, 3, 4, 5)
    
    scala> res0.filter(_ != 2)
    res1: List[Int] = List(1, 3, 4, 5)
    

    You want to use map when you are transforming all the elements of a list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have import scala.collection.immutable.TreeMap val tree = new TreeMap[String, List[String]] Now after above
Can I use scala List in Java, like : import scala.collection.immutable.List; class HelloScalaList {
In Programming in scala it is stated that lists are immutable and arrays are
I'm trying to figure out if I can convert List(Vector(1), Vector(2,3)) to Vector(List(1), List(2,3))
Some claim that appending to immutable lists is more efficient. Is this true? How?
I've spent a good hour googling, and can find various .NET immutable Lists, Sets
This line causes a compile error: astgen.typeError.foreach(System.err.println) typeError is a scala.collection.immutable.List of Strings in
I'm very new to Scala, so forgive my ignorance! I'm trying to iterate of
List has 2 methods that are specified to prepend an element to an (immutable)
The following is possible in Scala: scala> val l = List l: scala.collection.immutable.List.type =

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.