Scala - How to convert a Java Map to a Scala Map using JavaConverters? Code Example

The code for How to convert a Java Map to a Scala Map using JavaConverters?

import java.util._
import scala.collection.JavaConverters._

object Example {
    def main(args: Array[String]) = {
        val javaMapRecord = new HashMap[String, String]()
        javaMapRecord.put("First_Name", "Pranit")
        javaMapRecord.put("Second_Name",  "Sharma")
        
        // Converting java map to a Scala map
        val scalaMapRecord = javaMapRecord.asScala
        
        // Prinitng 
        println(scalaMapRecord)
    }
}    

/*
Output:
Map(First_Name -> Pranit, Second_Name -> Sharma)
*/
Code by IncludeHelp, on August 13, 2022 22:34

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.