What is the difference between scala :::
and ++
operator? According to the doc the behaviour is the same.
The difference is in the types that they accept. ::: only accepts a List . ++ accepts is a range of types from [B >: A, That] meaning that ++ will accept a type whose lower bound is List and upper bound is GenTraversableOnce[B] and types in between.
The difference between both the concatenation operators is that the + creates a new list and the += modifies an existing list in place.
The ::: operator in Scala is used to concatenate two or more lists. Then it returns the concatenated list.
They do the same thing, except that ++
can be used with any Traversable
and :::
can only be used with lists. Also, methods that end with :
are called on the object to the right, so that :::
's argument is the prefix while ++
's argument is the suffix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With