Difference between a Seq and a List in Scala

前端 未结 5 1114
不思量自难忘°
不思量自难忘° 2020-11-29 14:26

I\'ve seen in many examples that sometimes a Seq is being used, while other times is the List...

Is there any difference, other than the former one being a Scala typ

5条回答
  •  自闭症患者
    2020-11-29 14:57

    A Seq is an Iterable that has a defined order of elements. Sequences provide a method apply() for indexing, ranging from 0 up to the length of the sequence. Seq has many subclasses including Queue, Range, List, Stack, and LinkedList.

    A List is a Seq that is implemented as an immutable linked list. It's best used in cases with last-in first-out (LIFO) access patterns.

    Here is the complete collection class hierarchy from the Scala FAQ:

提交回复
热议问题