How to get Scala List from Java List?

前端 未结 6 1275
半阙折子戏
半阙折子戏 2021-01-29 23:23

I have a Java API that returns a List like:

public List getByXPath(String xpathExpr)

I am using the below scala code:

         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 23:39

    I was looking for an answer written in Java and surprisingly couldn't find any clean solutions here. After a while I was able to figure it out so I decided to add it here in case someone else is looking for the Java implementation (I guess it also works in Scala?):

    JavaConversions.asScalaBuffer(myJavaList).toList()
    

提交回复
热议问题