error value update is not a member of scala collection immutable Map String Int

0 votes

 Trying to update value of an immutable Map, Scala outputs an error. On the other hand, any changes made in value of any key in case of mutable Maps is accepted. How?

Updating immutable Map:

// Scala map program of 

// Updating the values

// in immutable map

  

// Creating an object

object GFG

{

    // Main method

    def main(args:Array[String])

    {

  

        val mapIm = Map("Ajay" -> 30, 

                        "Bhavesh" -> 20, 

                        "Charlie" -> 50)

              

        println(mapIm)

          

        //Updating

        mapIm("Ajay") = 10 

  

        println(mapIm)

  

    }

}
Output:
error: value update is not a member of scala.collection.immutable.Map[String, Int]

Any help will be great.

Nov 17, 2020 in Big Data Hadoop by anonymous
• 8,910 points
5,322 views

1 answer to this question.

0 votes

Yes, If you try to update the value of an immutable Map, Scala outputs an error. On the other hand, any changes made in the value of any key in the case of mutable Maps are accepted.

Updating mutable Map:

// Scala map program of 

// Updating the values

// in mutable map

  

// Creating Object

object GFG

{

      

    // Main method

    def main(args:Array[String])

    {

  

        val mapMut = scala.collection.mutable.Map("Ajay" -> 30,

                                                  "Bhavesh" -> 20, 

                                                  "Charlie" -> 50)

        println("Before Updating: " + mapMut)

  

        // Updating

        mapMut("Ajay") = 10 

  

        println("After Updating: " + mapMut)

    }

}

Output:

Before Updating: Map(Ajay -> 30, Charlie -> 50, Bhavesh -> 20)
After Updating: Map(Ajay -> 10, Charlie -> 50, Bhavesh -> 20)

Hope this helps!

If you want to know more about Apache Spark Scala, It's highly recommended to go for Spark certification course today.

Thanks!!

    answered Nov 17, 2020 by Gitika
    • 65,890 points

    Related Questions In Big Data Hadoop

    0 votes
    1 answer

    Error: Couldn't properly initialize access to HDFS internals. Please update your WAL Provider to not make use of the 'asyncfs' provider.

    Hi@akhtar, I think you are trying to use AsyncFSWAL for HBase-2.x as ...READ MORE

    answered Apr 30, 2020 in Big Data Hadoop by MD
    • 95,460 points
    1,508 views
    0 votes
    1 answer

    Which of the following is not a hadoop output format?

    The Hadoop Output Format checks the Output ...READ MORE

    answered Dec 20, 2021 in Big Data Hadoop by Kavya
    • 700 points
    1,783 views
    0 votes
    1 answer

    What is a importance of Hive ODBC Connector

    The Cloudera ODBC Driver for Hive enables ...READ MORE

    answered Apr 10, 2018 in Big Data Hadoop by kurt_cobain
    • 9,390 points
    821 views
    +1 vote
    2 answers
    0 votes
    1 answer

    Scala: 30: error: value partitions is not a member of String

    Try this code: val rdd= sc.textFile (“file.txt”, 5) rdd.partitions.size Output ...READ MORE

    answered Jul 29, 2019 in Apache Spark by Nijit
    3,225 views
    +1 vote
    1 answer

    Hadoop Mapreduce word count Program

    Firstly you need to understand the concept ...READ MORE

    answered Mar 16, 2018 in Data Analytics by nitinrawat895
    • 11,380 points
    10,911 views
    0 votes
    1 answer

    hadoop.mapred vs hadoop.mapreduce?

    org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

    answered Mar 16, 2018 in Data Analytics by nitinrawat895
    • 11,380 points
    2,444 views
    0 votes
    1 answer

    Error is not recoverable: exiting now

    Hey, While installing any file first thing: please confirm ...READ MORE

    answered May 13, 2019 in Big Data Hadoop by Gitika
    • 65,890 points
    814 views
    0 votes
    1 answer

    What is the command to know the details of your data created in a table in Hive?

    Hey, Yes, there is a way to check ...READ MORE

    answered May 15, 2019 in Big Data Hadoop by Gitika
    • 65,890 points
    1,435 views
    webinar REGISTER FOR FREE WEBINAR X
    REGISTER NOW
    webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP