Scala中Array和List的区别
展开全部
Arrays are mutable, indexed collections of values. Array[T] is Scala's representation for Java's T[].
Array:
可变
用下标访问,利于随机访问
是Java数组的一种表示
List is a class for immutable linked lists representing ordered collections
of elements of type A.This class comes with two implementing case classes scala.Nil and scala.:: that implement the abstract members isEmpty, head and tail.This class is optimal for last-in-first-out (LIFO), stack-like access patterns. If you need another access
pattern, for example, random access or FIFO, consider using a collection more suited to this than List.
List:
不可变
为后进先出做了优化,像栈一样的访问模式
支持用::在模式匹配中取出head和tail
Array:
可变
用下标访问,利于随机访问
是Java数组的一种表示
List is a class for immutable linked lists representing ordered collections
of elements of type A.This class comes with two implementing case classes scala.Nil and scala.:: that implement the abstract members isEmpty, head and tail.This class is optimal for last-in-first-out (LIFO), stack-like access patterns. If you need another access
pattern, for example, random access or FIFO, consider using a collection more suited to this than List.
List:
不可变
为后进先出做了优化,像栈一样的访问模式
支持用::在模式匹配中取出head和tail
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询