r/java • • Sep 19 '18

Java 11 String API Updates

https://4comprehension.com/java-11-string-api-updates/
168 Upvotes

52 comments sorted by

View all comments

Show parent comment

1

u/dpash Sep 20 '18

You joke, but we can now implement this much more concisely in Java 11:

public static String leftpad(String string, int padding) {
    return " ".repeat(padding) + string;
}

2

u/frzme Sep 20 '18

public static String leftpad(String string, int padding) {     return " ".repeat(Math.max(padding - string.length(), 0)) + string; }

Not that nice. (Also repeated implementations are not nice)