Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the differences between:, +,:, +,:, + in scala

Shulou Source: shulou.com Published: 2022-06-02 11:04:35 09月29日 Update

This article mainly introduces the differences between scala::, +:,::, +, what is introduced in the article is very detailed, has a certain reference value, interested friends must read it!

The difference and relation of the four operators

:: this method is called cons, which means to construct, append data to the header of the queue and create a new list. The usage is x::list, where x is the element added to the header. Whether x is a list or not, it will only become the first element of the newly generated list, that is, the length of the newly generated list is + 1 (btw, x::list is equivalent to list.:: (x)).

: + and +: the difference between the two is that the + method is used to append elements to the tail, and the +: method is used to append elements to the header, which is similar to::, but:: can be used for pattern match, while +: is not. As for +: and: +, just remember that colons are always close to the collection type and OK.

+ + this method is used to join two sets, list1++list2.

: this method can only be used to join two collections of List type

Specific example scala > "A":: "B": Nilres0: List [String] = List (A, B) scala > "A" +: "B" +: Nilres1: List [String] = List (A, B) scala > Nil:+ "A": + "B" res2: List [String] = List (A, B) scala > res0 + + res1res3: List [String] = List (A, B, A, B) scala > res0:: res1res4: List [String] = List (A, B, A) B) scala > res0:: res1res5: List [java.io.Serializable] = List (List (A, B), A, B) these are all the contents of the article "what are the differences in scala::, +:,::, +" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Method element two content head freshman article type length no that is value interest colon boy partner tail meaning operator Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MySQL Shulou Tech Info Xiaomi Apple