Answers for "padding string value java"

3

padding a string with 0 in java

String.format("%05d", yournumber);
//%05 means length of 5
// 25 becomes 00025
Posted by: Guest on March-29-2020
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