Kotlin Function Return 2 Values (Tuple)

June 20, 2018

You can use destructure declaration.

fun return2Values(): Array<String> {
    return arrayOf("hello", "world")
}

val (firstWord, secondWord) = return2Values()

Alternatively, you can consider using sealed classes for more advance usage.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.