September 2015
Intermediate to advanced
250 pages
6h 40m
English
String in Scala is simply java.lang.String. You can use String just like you do in Java. However, Scala does provide a few additional conveniences when working with String.
Scala can automatically convert a String to scala.runtime.RichString. This brings a few useful methods like capitalize, lines, and reverse to String.
It’s really simple in Scala to create a string that runs multiple lines—no more of those messy +=. Place the multiple lines of strings within three double quotes ("""…"""). That’s Scala’s support for the so-called here documents, or heredocs. To see it in action, let’s create a string that runs a few lines long:
| FromJavaToScala/MultiLine.scala | |
| | val str = """In his famous inaugural speech, ... |
Read now
Unlock full access