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

前端 未结 4 1965
迷失自我
迷失自我 2020-12-21 02:42

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 progra

4条回答
  •  攒了一身酷
    2020-12-21 03:27

    Just import scala.collection.JavaConversions and you should be set :) It performs conversions from Scala collections to Java collections and vice-versa.

    If it doesn't work smoothly, try:

    val m: Map[String,List[String]] = javaMap
    

    You might also need to convert each one of the lists inside the map:

    m.map {
      l => val sl: List[String] = l
      sl
    }
    

提交回复
热议问题