Tips and Traps¶
- Notice that Iterable.map
returns a List instead of an iterator.
Since almost all collections in Kotlin eventually inherit from
Iterable, themapmethod of all collections (includingHashMap) in Kotlin returns List.
List in Kotlin
Create an Empty List¶
Sort a List in Kotlin
sorted¶
If elements in a List implements the Comparable interface,
you can call the method sorted to return a sorted List (in nature order).
Note: Pair in Kotin does not implement the Comparable interface!!!
Returns and Jumps in Kotlin
Break at label is a convenient way to jump out of a nested loop.