How to convert String to Long in Kotlin?

前端 未结 11 1012
旧时难觅i
旧时难觅i 2021-01-31 13:00

So, due to lack of methods like Long.valueOf(String s) I am stuck.

How to convert String to Long in Kotlin?

11条回答
  •  清歌不尽
    2021-01-31 13:36

    If you don't want to handle NumberFormatException while parsing

     var someLongValue=string.toLongOrNull() ?: 0
    

提交回复
热议问题