java.util.Iterator to Scala list?

前端 未结 5 1642
走了就别回头了
走了就别回头了 2021-02-12 13:16

I have the following code:

private lazy val keys: List[String] = obj.getKeys().asScala.toList

obj.getKeys returns a java.uti

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-12 14:05

    Note that starting Scala 2.13, package scala.jdk.CollectionConverters replaces deprecated packages scala.collection.JavaConverters/JavaConversions when it comes to implicit conversions between Java and Scala collections:

    import scala.jdk.CollectionConverters._
    
    // val javaIterator: java.util.Iterator[String] = java.util.Arrays.asList("a", "b").iterator
    javaIterator.asScala
    // Iterator[String] = 
    

提交回复
热议问题