String
In this page:
String
A String is an immutable sequence of characters, written with double quotes. Strings support concatenation with +, a rich set of built-in methods, and interpolation with s"..." (covered in its own tutorial). Because strings are immutable, every "modification" actually creates a new string.
Note: Prefer string interpolation (s"Hello $name") over + concatenation for readability.
Example: String
object Main extends App {
val first = "Ada"
val last = "Lovelace"
val full = first + " " + last
println(full)
println(full.length)
println(full.toUpperCase)
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: