1

I am trying to convert a map from scala to java:

private def toJava(map: Map[Int, Set[Int]]): util.Map[Integer, util.Set[Integer]] = {
    scala.collection.JavaConverters.mapAsJavaMapConverter(
      map.mapValues(scala.collection.JavaConverters.setAsJavaSetConverter(_).asJava)).asJava
}

However, the Int is not converted to Integer, And I don't find the way to achieve that.

What is the scala way to do it?

oshai
  • 14,865
  • 26
  • 84
  • 140
  • 1
    `import scala.collection.JavaConverters._` `private def toJava(map: Map[Int, Set[Int]]): java.util.Map[Integer, java.util.Set[Integer]] =` `mapAsJavaMapConverter(map.mapValues(setAsJavaSetConverter(_).asJava))` `.asJava.asInstanceOf[java.util.Map[java.lang.Integer, java.util.Set[Integer]]]` – Yuriy Tumakha Dec 13 '15 at 18:02
  • 2
    I don't think it is a duplicate of the referenced question. I think it is SO and scala interest to have more questions that are related. – oshai Dec 13 '15 at 20:04
  • 1
    @NisseEngström - it is easy to notice that it is not "straight forward" to understand the solution to one question from the other - although they are similar, this one is a bit more complicated (collection inside a collection). – oshai Dec 13 '15 at 22:20
  • Someone wants to get answer. Why another one close it as duplicate without clear answer? Is the main goal of website to get answer and to help people? – Yuriy Tumakha Dec 14 '15 at 08:36
  • @oshai For posterity, You can add correct code to your post with label **Answer** – Yuriy Tumakha Dec 14 '15 at 10:47

0 Answers0