InScala 2.7in whichArray,Listcannot mix types, onlyTupleYes, and in Scala,3 elements can be mixed with different types (into any type), except when using mixed types. The array and list convert the element type to any type, while the tuple retains the initial type of each element ;
About Array,list,tuple
-
About initializing
1) Val array= new Array[string] (3)// array (NULL, NULL, NULL) is equivalent to a null element that declares 3 null values
val array= Array ("A", "B", "C", "D")// equivalent array.apply ("A", "B", "C", "D")
defines a type of any of the Array :
val AA = Array[any] (1, 2) val aa:array[any] = Array (1, 2) or: val aa:array[_] = Array (1, 2)
2) V [ int = List (1,3,4,5,6)// v al list = List (1,3,4,5,6)
(:::) implements the overlay list, (::) Cons: Combines the new elements into the front of the list. The element is merged using::, the collection is merged using:::, an example is as follows: where nil represents an empty element
val List2 = "A":: "B":: "C":: Nil//nil
v al list4 = list2:::list3
3)tuples are immutable, but tuples can be different types of data, instantiation: var a = (,), you can access elements by dot, underscore,-N (N 1-based) index
Scala's differences about Array,list,tuple