Java String.format alternative in kotlin?


#1

Hi,

I’m using java String.format in my codes which i want to port to kotlin.
For example
String log = String.format("%d, %s, %6f : %3f", value1, value2, value3, value4)

How to convert above java code to kotlin?

Thanks


#2

You can use java String

fun main(args : Array<String>) {   var value1 = 1   var value2 = "2"   var value3 = 3.0   var value4 = 4.0   println(java.lang.String.format("%d, %s, %6f : %3f", value1, value2, value3, value4)) }


#3

Thank you for your reply. It works.


#4

You can also write

println("%d, %s, %6f : %3f".format(value1, value2, value3, value4))