Iterating over Java collections in Scala

前端 未结 9 1307
不思量自难忘°
不思量自难忘° 2020-11-28 02:19

I\'m writing some Scala code which uses the Apache POI API. I would like to iterate over the rows contained in the java.util.Iterator that I get from the Sheet

9条回答
  •  有刺的猬
    2020-11-28 02:46

    Edit: Scala 2.13.0 deprecates scala.collection.JavaConverters, so since 2.13.0 you need to use scala.jdk.CollectionConverters.

    Scala 2.12.0 deprecates scala.collection.JavaConversions, so since 2.12.0 one way of doing this would be something like:

    import scala.collection.JavaConverters._
    
    // ...
    
    for(k <- javaCollection.asScala) {
        // ...
    }
    

    (notice the import, new is JavaConverters, deprecated is JavaConversions)

提交回复
热议问题