1

Scala 提供了如此多的集合......我不确定该使用哪一个。

我的函数生成一组预定义数量的元素,这些元素将按其原始顺序逐个迭代。

所有 immutable VectorSeqList支持迭代,但我应该使用哪一个?

4

1 回答 1

0

您正在寻找一个维持秩序的收藏品。任何扩展的集合都seq保持添加元素的顺序。

[scaladocs] Sequences have two principal subtraits, IndexedSeq and LinearSeq, which give different guarantees for performance. An IndexedSeq provides fast random-access of elements and a fast length operation. A LinearSeq provides fast access only to the first element via head, but also has a fast tail operation

List延伸LinearSeq,而Vector延伸IndexedSeq

在这些之间进行选择将取决于您希望如何访问数据以及您希望对数据执行的操作。

于 2013-02-26T09:17:24.303 回答