Converting a Java collection into a Scala collection

后端 未结 10 1543
Happy的楠姐
Happy的楠姐 2020-11-29 17:35

Related to Stack Overflow question Scala equivalent of new HashSet(Collection) , how do I convert a Java collection (java.util.List say) into a Scala c

10条回答
  •  没有蜡笔的小新
    2020-11-29 18:00

    You can add the type information in the toArray call to make the Set be parameterized:

     val s = Set(javaApi.query(....).toArray(new Array[String](0)) : _*)
    

    This might be preferable as the collections package is going through a major rework for Scala 2.8 and the scala.collection.jcl package is going away

提交回复
热议问题