[英]Prepending to mutable.LinkedList without copying in Scala
I need to build up a list very quickly. 我需要很快建立一个清单。 My idea was to use a mutable.LinkedList and grow by prepending.
我的想法是使用mutable.LinkedList并通过前缀进行扩展。 However I found only the operator +: for prepending and it produces a copy of the list, which is surprising, given that the list is mutable.
但是我发现只有运算符+:作为前缀,它会生成列表的副本,这令人惊讶,因为列表是可变的。
Is there a way to prepend and modify the list in place? 有没有办法在列表前添加和修改列表?
I think this is how you are supposed to use it, from a quick glance: 我认为这是您应该使用的方式,快速浏览一下:
val newList = new LinkedList(newElem, existingList)
Note though that it is deprecated in Scala 2.11 and might get removed in the future. 请注意,尽管它在Scala 2.11中已弃用,但将来可能会被删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.