scala dynamic multi dimensional mutable arrays like datastructures

前端 未结 3 1647
长情又很酷
长情又很酷 2021-02-06 01:15

Is there any way to build dynamic multi-dimensional arrays in Scala? I know arrays in Scala must be initialized in its sizes and dimensions, so I don\'t want that. The data stru

3条回答
  •  佛祖请我去吃肉
    2021-02-06 01:36

    Well, it depends a lot on what you intend to do with it, but your best guess is IndexedSeq[IndexedSeq[T]] (or deeper nestings), using Vector as the implementation for IndexedSeq (it's the default implementation anyway).

    For example:

    scala> IndexedSeq(IndexedSeq(1, 2, 3), IndexedSeq(4, 5), IndexedSeq(6, 7, 8, 9)) res0: IndexedSeq[IndexedSeq[Int]] = Vector(Vector(1, 2, 3), Vector(4, 5), Vector(6, 7, 8, 9))

提交回复
热议问题