1.Tuple
The Chinese meaning of a tuple is a tuple, and its definition is that no method is required.
For example: Val tup= ("Tuple", "Map", "Array").
It is important to note that when a tuple is indexed, there are a number of different points to the array we see in the usual way, and it is indexed by: underscore and a 1-based element index. (There is a special emphasis on cardinality, because in Java, C + +, when we define arrays, we start with 0)
Object Tupleops {
def Main (args:array[string]): unit={
Val tuples= (2, "Tuple", "Map", "Array")
println (tuples._1)
println (tuples._2)
println (Tuples._3)
}
}
2.Map
Map is the map. We can interpret it as an associative array. Map is a dual set, through the map class construction, with the "-" operator to connect the dual key-value pairs, below we define a mapping set.
For example Valmap=map ("Xiaoming"->1, "Xiaomei"->2, "Xiaofang"->3).
For the index of the map map, we usually use a for loop to assign a key-value pair through (key,value) <-map. It is then displayed by outputting key and value. Object Mapops {
def Main (args:array[string]): unit={
val maps=Map("Xiaoming"->1, "Xiaomei"->2, "Xiaofang"->3)
for ((key,value) <-maps) {
println ("Key is:" +key+, "value is:" +value)
}
println ("____________________________________________________")
for ((key,_) <-maps) {
println ("Key is:" +key)
}
}
}
3.Array
For the array, we are relatively familiar with learning java,c++, and here I will not repeat more. However, I would like to highlight a bit in Scala, where array loops out in two ways.
Arrayops {
Main (args:array[string]): unit={
arrays=Array(1,2,3,4)
println ("First output mode:")
for (i<-0 until Arrays.length) {
println (Arrays (i))
}
println ("____________________________________")
println ("Second output type (recommended):")
for (elem<-arrays) {
println (Elem)
}
}
}
The tuple, Map, and Array of Scala learning