Padding string in Kotlin

Viewed 8105

I was trying to pad a string in Kotlin to achieve some proper alignment on the console output. Something along these lines:

accountsLoopQuery                             - "$.contactPoints.contactPoints[?(@.contactAccount.id)]"
brokerPassword                                - *****
brokerURI                                     - tcp://localhost:61616
brokerUsername                                - admin
contactPointPriorityProperties                - "contactPointPriority.properties"
customerCollection                            - "customer"
customerHistoryCollection                     - "customer_history"
defaultSystemOwner                            - "TUIGROUP"

I have ended up coding it this way - cheating with Java's String.format:

mutableList.forEach { cp ->
    println(String.format("%-45s - %s", cp.name, cp.value))
}

Is there a proper way to do this with the Kotlin libraries?

2 Answers
Related