
上QQ阅读APP看书,第一时间看更新
Converting string to Long using string.toLongOrNull()
In this example, we will see how we can parse a string using the .toLongOrNull() method:
fun main(args: Array<String>) {
val str="123.4"
val str2="123"
println(str.toLongOrNull())
println(str2.toLongOrNull())
}
On running the preceding program, the following output is generated:
null 123