In my Scala function, i'm traversing a Java ArrayCollection, extracting specific elements which should form a new collection. At the end, it has to be a Java-ArrayList again, because i'm interacting with a Java Framework. My Code:
// to make scala-style iterating over arraylist possible
import scala.collection.JavaConversions._
// ArrayList contains elements of this type:
class Subscription(val subscriber:User, val sender:User)
// I'm getting this list from Java:
val jArrayList = new ArrayList[Subscription]
// Buffer:scala.collection.mutable.Buffer[User]
val buffer = for (val subscription <- jArrayList ) yield subscription.sender
How can i convert the Buffer to an ArrayList[User]? Or shouldn't i use yield here?
scala.jdk.CollectionConverters
instead – Dora