① :: It is used to append data to the head of the queue and generate a new list. x::list, x will be added to the head of the list.
.:: This is a method of list; its function is the same as above, adding elements to the head position; list.::(x)
② ::: Used to connect two List type collections
③ :+ is used to append elements to the end of the list; list :+
④ +: used to add elements to the head of the list
⑤ ++ is used to connect two collections, list1++list2
scala> val b:List[Int] = List(10,23,45)
b: List[Int] = List(10, 23, 45)
scala> b :: 1
<console>:26: error: value :: is not a member of Int
b :: 1
^
scala> 1 :: b
res30: List[Int] = List(1, 10, 23, 45)
scala> b.::(2)
res31: List[Int] = List(2, 10, 23, 45)
scala> 2.::b
<console>:24: error: value :: is not a member of Int
2.::b
^
scala> b:+6
res33: List[Int] = List(10, 23, 45, 6)
scala> 7+:b
res34: List[Int] = List(7, 10, 23, 45)
scala> val c:List[Int]=List(32,54)
c: List[Int] = List(32, 54)
scala> b ++ c
res35: List[Int] = List(10, 23, 45, 32, 54)
scala> val d:Array[String] = Array("A","B","C")
d: Array[String] = Array(A, B, C)
scala> d ++ b
res36: Array[Any] = Array(A, B, C, 10, 23, 45)
scala> d ::: b
<console>:28: error: type mismatch;
found : Array[String]
required: List[?]
d ::: b
^