The main advantage is that it allows String to be treated as a sequential character set, like any other Seq or List instance.
In fact, these methods (and other important transformation functions such as map, flatMap, and filter) are not implemented in String itself (it is, in fact, just a Java String class, not a native-Scala class), but in a StringOps class (which extends StringLike â ... â SeqLike), and the implicit conversion ensures that String is converted to StringOps whenever you need access to these methods.
This means that you can pass String to the list management function, and the function will receive an instance of StringOps, working on it like any other SeqLike object, without having to know that it is actually a string, and send the results that StringOps is intended to be presented to you as a string.
If you know that an entity is a string in a given piece of code, feel free to use String-specific methods, but the availability of this implicit conversion means that you can also use the String character sequence - like any other list, in situations when it can be convenient.
Shadowlands
source share