Answers for "pad string java"

2

java string padding

Have a look at org.apache.commons.lang.StringUtils#rightPad(String str, int size, char padChar).

But the algorithm is very simple (pad right up to size chars):

public String pad(String str, int size, char padChar)
{
  StringBuilder padded = new StringBuilder(str);
  while (padded.length() < size)
  {
    padded.append(padChar);
  }
  return padded.toString();
}
Posted by: Guest on September-20-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language