Fastest padLeft-function in Java
Since Java does not have a function to pad strings on the left or right side, you either have to program such function yourself or use an existing library, such as Apache Commons. Because I recently needed a function that would pad a numeric string on the left side (= padLeft) with zeros up to a length of 8 characters, but did not want to include a whole library for such a simple task, the only option was to write a padLeft function myself.
However, when researching and implementing, I found various solution approaches and so I ended up with six different padLeft implementations. In order to find the best padLeft function for my use case, I tested all six implementations during a small performance test and found the fastest padLeft function. Before I […]