Simple to use Scala sequence of --List

Scala> Import scala.collection.immutable._
Import scala.collection.immutable._
// create immutable sequence
Scala> Val = LST1 List (l, 2,3)
LST1: List [Int] List = (. 1, 2 , 3)

// 0 is inserted into the front LST1 and generate a new set of
Scala> 0 :: = LST1 Val Ls2
Ls2: List [Int] List = (0,. 1, 2,. 3)

// 0 is inserted into the front lst1 and generate a new set of
Scala> = Val Ls3 are lst1.::(0)
Ls3 are: List [Int] List = (0,. 1, 2,. 3)
// 0 is inserted into the lst1 front and generates a new set of
Scala> = 0 + Val LS4: LST1
LS4: List [Int] List = (0,. 1, 2,. 3)
// 0 is inserted into the front LST1 and generate a new set
scala> val + :( 0 = LST1 LS5).
LS5: List [Int] List = (0,. 1, 2,. 3)

// After 3 into LST1 and generate a new set of
Scala> Val LS6 = LST1: +3
LS6: List [Int] List = (. 1, 2, 3, 3)

// Create a list set
Scala> Val LS7 List = (4,5,6)
LS7: List [Int] List = (. 4,. 5,. 6)

The combined to form a new set of set
Scala> Val = LST1 ++ LS7 LS8
LS8: List [Int] List = (. 1, 2,. 3,. 4,. 5,. 6)

LS7 inserted into the front lst11
Scala> Val LS9 LS7 :( :: = LST1).
LS9: List [Int] List = (. 4,. 5,. 6,. 1, 2,. 3)
printouts
Scala> the println (LS9)
List ( 4, 5, 6, 1, 2, 3)

// Create a set li1
Scala> Val li1. 1 =: :( 2: :(. 3: :( :: Nil. 4)))
li1: List [Int] List = (. 1, 2,. 3,. 4)

// Create a set li2
Scala> Val li2. 1 :: = 2. 4 :: :: ::. 3 Nil
li2: List [Int] List = (. 1, 2,. 3,. 4)

// determines whether an empty
Scala> li2.isEmpty
Res 66: = Boolean to false

// take the first element
Scala> li2.head
res67: Int. 1 =

// get the remaining elements except the first element returns a list of
Scala> li2.tail
res68: List [Int] = List (2,. 3,. 4)

// get the list of the second element
Scala> li2.tail.head
res69: Int = 2

// operatively connected
Scala> List (l, 2,3) ::: List (4,5,6)
res70: List [Int] List = (. 1, 2,. 3,. 4,. 5,. 6)

// Take 1 element except the last element, returns a list of
Scala> li2.init
res71: List [Int] List = (1, 2,. 3)

// get the last element of the list
Scala> li2.last
res72: Int. 4 =

Inverted list element
Scala> li2.reverse
res74: List [Int] List = (. 4,. 3, 2,. 1)

It determines whether or equal
Scala> == li2.reverse.reverse LI2
res75: = Boolean to true

// remove the remaining element other than the first inverted
Scala> li2.tail.reverse
res77: List [Int] List = (. 4,. 3, 2)

scala> li2.reverse.init
res78: List[Int] = List(4, 3, 2)

// delete elements
Scala> LI2 drop 2
res79: List [Int] List = (. 3,. 4)

// Get a front element
Scala> Take LI2. 1
res80: List [Int] List = (. 1)

// Get the first three elements
Scala> li2.take (. 3)
res81: List [Int] List = (. 1, 2,. 3)

// List segmentation
Scala> li2.splitAt (2)
res82: (List [Int], List [Int]) = (List (. 1, 2), List (. 3,. 4))

scala> (li2.take(2),li2.drop(2))
res83: (List[Int], List[Int]) = (List(1, 2),List(3, 4))

scala> val la1=List(1,2,3,4)
la1: List[Int] = List(1, 2, 3, 4)

scala> val chars=List(‘1’,‘2’,‘3’,‘4’)
chars: List[Char] = List(1, 2, 3, 4)

// list element array
Scala> La1 ZIP chars
res85: List [(Int, Char)] List = ((1,1), (2,2 &), (3,3), (4,4 &))

list.toStrin方法
scala> la1.toString
res86: String = List(1, 2, 3, 4)

Printout
Scala> la1.mkString
res88: String = 1234

scala> la1.toArray
res89: Array[Int] = Array(1, 2, 3, 4)

Guess you like

Origin blog.csdn.net/weixin_44701192/article/details/91475965