As a brief note today, here’s a Scala method to generate a random string that is random length and also contains blank spaces:
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.
Today I needed a Java method to remove all the blank characters from a
String. I started to write some code with a StringBuffer or a StringBuilder, then thought there must be some other way to do this. It’s not that the StringBuilder/StringBuffer approach is hard, but just that someone must have already solved this problem.
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