To convert a list of strings to a list of floats in Kotlin, you can use the toFloat()
method to parse each string as a float.
In this example,
stringList
.toFloat()
method to parse it as a float.fun main() {
val stringList = listOf("1.1", "2.2", "3.3", "4.4", "5.5")
val floatList = stringList.map { it.toFloat() }
println(floatList)
}
[1.1, 2.2, 3.3, 4.4, 5.5]
In this tutorial, we learned How to Convert a List of Strings to a List of Floats in Kotlin language with well detailed examples.