In this article, we will see how to convert int to String in Kotlin.
Kotlin doesn’t do automatic type conversions.
For converting int to String, we need to use the Int.toString method.
fun main(args: Array<String>) { var num:Int = 10 var str:String = num.toString() print("Type of str is ${str::class.simpleName}") }
Output:
Type of str is String
Similarly we can use toString to convert other datatypes as shown below :
To convert Byte to String in Kotlin, use Byte.toString()
To convert Short to String in Kotlin , use Short.toString()
To convert Long to String in Kotlin, use Long.toString()
© 2018, https:. All rights reserved. On republishing this post, you must provide link to original post
[…] How to convert int to String in Kotlin […]