How to convert Java LinkedHashMap to Scala LinkedHashMap?
NickName:miniscule001 Ask DateTime:2016-10-13T04:33:08

How to convert Java LinkedHashMap to Scala LinkedHashMap?

I'm new to Scala. I've been trying to convert a java LinkedHashMap to an equivalent collection(LinkedHashMap?) in Scala in order to preserve the insertion order.

Tried following things as suggested in other threads, but nothing seems to work!

scalaAsMap() - is messing up the order

TreeMap() - sort on keys, values, etc. is not something I'm looking for

Explicit conversion is not working.

val f = new java.util.LinkedHashMap[String, java.util.Map[String, String]]

var g: scala.collection.mutable.LinkedHashMap[String, java.util.Map[String, String]] = f

Copyright Notice:Content Author:「miniscule001」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40007857/how-to-convert-java-linkedhashmap-to-scala-linkedhashmap

More about “How to convert Java LinkedHashMap to Scala LinkedHashMap?” related questions

How to convert Java LinkedHashMap to Scala LinkedHashMap?

I'm new to Scala. I've been trying to convert a java LinkedHashMap to an equivalent collection(LinkedHashMap?) in Scala in order to preserve the insertion order. Tried following things as suggest...

Show Detail

How would I convert to linkedhashmap to a java type?

I am using a java API that requires a linkedhashmap LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>(); Should I just use the scala version and then conver...

Show Detail

How to convert java Map to scala Map of type LinkedHashMap[String,ArrayList[String]]?

from Java API I get java.util.LinkedHashMap[String,java.util.ArrayList[String]] which I then need to pass as a parameter to a scala program val rmap = Foo.baz(parameter) This parameter is of s...

Show Detail

Java LinkedHashMap to scala Map conversion and recursive conversion

If mapAsScalaMap is an implicit function then why do we have to use it explicitly? And why is recursive conversion not happening ? import scala.collection.JavaConversions._ val javaObj = yamlObj.

Show Detail

Remove eldest entry from scala LinkedHashMap

I'm trying to use scala's LinkedHashMap as an LRU cache, but I'm not sure how to remove the oldest entry of such a map. I know java's LinkedHashMap has a method removeEldestEntry, but there does no...

Show Detail

Merge two LinkedHashMap in Scala

Having this code def mergeWith[K, X, Y, Z](xs: mutable.LinkedHashMap[K, X], ys: mutable.LinkedHashMap[K, Y])(f: (X, Y) => Z): mutable.LinkedHashMap[K, Z] = xs.flatMap { case (k, x) => ...

Show Detail

Casting java.util.LinkedHashMap to scala.collection.mutable.Map

import scala.collection.JavaConversions._ val m = new java.util.LinkedHashMap[String,Int] val s: scala.collection.mutable.Map[String,Int] = m.asInstanceOf[scala.collection.mutable.Map[String,Int]]

Show Detail

workaround for prepending to a LinkedHashMap in Scala?

I have a LinkedHashMap which I've been using in a typical way: adding new key-value pairs to the end, and accessing them in order of insertion. However, now I have a special case where I need to ...

Show Detail

How to convert a Scala Spark Dataframe to LinkedHashMap[String, String]

Below is my dataframe: val myDF= spark.sql("select company, comp_id from my_db.my_table") myDF: org.apache.spark.sql.DataFrame = [company: string, comp_id: string] And the data looks like +-----...

Show Detail

java cast LinkedHashMap to class extending LinkedHashMap

I have a class (EntireFile) that extends the LinkedHashMap. I try to cast: EntireFile old = (EntireFile) functionReturningLinkedHashMap(); It throws exception with message: "java.util.LinkedHashMap

Show Detail