Scala functions to repeat a character n times (blank padding)

Earlier today I needed a function that would return a desired number of blank spaces so I could “pad” some output as desired. For some reason my mind went blank and I forgot about using a printf-style solution, and it quickly went to, “How can I write a Scala function to return n number of blank spaces?”

Note: If you just want the “best” solution, please scroll to the bottom of this article.

A Java method that tests if a String is null or blank

Problem: You're working on a Java application, and you're repeatedly performing a test to determine whether a String (or many strings) are either blank or null.


Create a simple Java method to perform this test for you. The following Java method returns true if a String is blank or null, otherwise it returns false: