July 2018
Intermediate to advanced
400 pages
12h 14m
English
The String type includes other functions that move through the sequence of characters one at a time, as indexOf and split do. For example, you can print each character of the tavern data, one character at a time, using String’s forEach function. This call:
"Dragon's Breath".forEach {
println("$it\n")
}
Would generate the following output:
D
r
a
g
o
n
'
s
B
r
e
a
t
h
Many of these functions are also available on the List type, just as the majority of the functions for traversing lists that you will learn about in Chapter 10 are also available for strings. In many ways, a Kotlin String behaves like a list of characters.
Read now
Unlock full access