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,880 points
189 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)
    answered Nov 17, 2020 by Gitika
    • 65,870 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,060 points
    276 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
    236 views
    +1 vote
    1 answer

    Why is jar file required to execute a MR code instead of class file?

    We use hadoop keyword to invoke the ...READ MORE

    answered Apr 24, 2018 in Big Data Hadoop by Shubham
    • 13,480 points
    236 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
    806 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
    6,814 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
    1,092 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,870 points
    163 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 14, 2019 in Big Data Hadoop by Gitika
    • 65,870 points
    537 views