How to get the second word of a string in Kotlin

1 Answer

0 votes
fun main() {
    val sentence = "Kotlin is a programming language that makes coding concise"

	val words = sentence.split(" ")

	val secondWord = if (words.size > 1) words[1] else "No second word"

	println(secondWord)
}

 
 
 
/*
run:

is
 
*/

 



answered Dec 19, 2024 by avibootz
...