When used for understanding, the base code uses map , flatMap , foreach , filter or withFilter - see related questions. In this particular example, this code will be equivalent to jArrayList.map(_.sender) , and map create new collections (I ignore the implicit conversion here to make it simple).
What is happening here is perhaps unintuitive, and perhaps one can improve, is that ArrayList does not implement map . An implicit conversion gives instead a Buffer , and a map on Buffer returns a Buffer .
Of course, Buffer on JavaConversions saves the base collection, ArrayList , as a backup storage. On the other hand, the created Buffer will not be based on this, but in one of Scala's own collections.
You can always do this:
val buffer = (for (val subscription <- jArrayList ) yield subscription.sender).asList
Daniel C. Sobral
source share