Skip to content

Instantly share code, notes, and snippets.

@Temidtech
Last active July 1, 2019 07:39
Show Gist options
  • Save Temidtech/fb9b1d7f8dcf38cfbf482f0b9b6fe5b2 to your computer and use it in GitHub Desktop.
Save Temidtech/fb9b1d7f8dcf38cfbf482f0b9b6fe5b2 to your computer and use it in GitHub Desktop.
val soloList: List<Any> = listOf("Wakanda forever!", "Kotlin is fire!",2018,29.3,12.2837827,true)
for(value in soloList) {
when (value) {
is String -> println("String: '$value'. Capitalize :${value.capitalize()}")
is Int -> println("Integer: '$value'")
is Double -> println("Double: '$value'")
is Float -> println("Float: '$value'")
else -> println("Unknown Type")
}
}
// Here is the Output
String: 'Wakanda forever!'. Capitalize :Wakanda forever!
String: 'Kotlin is fire!'. Capitalize :Kotlin is fire!
Integer: '2018'
Double: '29.3'
Double: '12.2837827'
Unknown Type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment