Are these two equivalent (just checking for any go...
# getting-started
m
Are these two equivalent (just checking for any gotchas)?
Copy code
if (text.length < 40) {
    // left pad with zeros
    text = String(CharArray(40 - text.length)).replace('\u0000', '0') + text
}
Copy code
text = text.padStart(40, '0')
m
yes, it seems equivalent. You can check the standard lib source: https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/text/Strings.kt#L154
👍 1
But why would you want to reimplement that?
m
Just converting over some old Java code
👍 1
m
Did you know that IntelliJ can try and convert code from Java to Kotlin? The output is mechanical, works good for most cases or to get an idea of how it can be written in Kotlin, but it’s not idiomatic. Some times you have to clean it afterwards or just rewrite it by hand.
m
I used the converter in AndroidStudio and the first snippet above, is what it spat out.
m
haha nice! Of course it’s not so smart to find a stdlib function to replace your old code… but sometimes it will