A very basic question, What is the right approach to concatenate String to an Int?
I'm new in Kotlin and want to print an Integer
value preceding with String and getting the following error message.
for (i in 15 downTo 10){
print(i + " "); //error: None of the following function can be called with the argument supplied:
print(i); //It's Working but I need some space after the integer value.
}
Expected Outcome
15 14 13 12 11 10
You've got several options:
1. String templates. I think it is the best one. It works absolutely like 2-st solution, but looks better and allow to add some needed characters.
print("$i")
and if you want to add something
print("$i ")
print("$i - is good")
to add some expression place it in brackets
print("${i + 1} - is better")
2. toString
method which can be used for any object in kotlin.
print(i.toString())
3. Java-like solution with concatenating
print("" + i)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With