scala - Converting mutable collection to immutable - Stack Overflow
If you want to convert ListBuffer
into a List
, use .toList
. I mention this because that particular conversion is performed in constant time. Note, though, that any further use of the ListBuffer
will result in its contents being copied first.
Otherwise, you can do collection.immutable.Seq(xs: _*)
, assuming xs is mutable, as you are unlikely to get better performance any other way.
Read full article from scala - Converting mutable collection to immutable - Stack Overflow
No comments:
Post a Comment