To convert an integer to a string in Kotlin, you can use the toString()
method of the Integer class.
In this example,
num
and assign it a value of 42
.num
to a string using the toString()
method and store the result in the variable strNum
.toString()
method converts the integer to its string representation.// Convert Integer to String
fun main() {
val num = 42
val strNum = num.toString()
println("String representation of integer: $strNum")
}
String representation of integer: 42
In this example,
negativeNum
with a value of -10
.negativeNum
to a string using the toString()
method and store the result in the variable strNegativeNum
.toString()
method converts the integer to its string representation.// Convert Negative Integer to String
fun main() {
val negativeNum = -10
val strNegativeNum = negativeNum.toString()
println("String representation of negative integer: $strNegativeNum")
}
String representation of negative integer: -10
In this tutorial, we learned How to Convert Integer to String in Kotlin language with well detailed examples.