Android Utililty Methods String Pad

List of utility methods to do String Pad

Description

The list of methods to do String Pad are organized into topic(s).

Method

StringtoPaddedString(String source, int length, char pad, boolean trailing)
to Padded String
int len = source.length();
if (len >= length) {
    return source;
StringBuffer sb = new StringBuffer(length);
if (trailing) {
    sb.append(source);
for (int i = len; i < length; i++) {
    sb.append(pad);
if (!trailing) {
    sb.append(source);
return sb.toString();
StringtoPaddedString(String source, int length, String pad, boolean trailing)
to Padded String
int len = source.length();
if (len == length) {
    return source;
if (len > length) {
    if (trailing) {
        return source.substring(0, length);
    } else {
...
StringpadLeft(String str, char padding, int upTo)
Pad a string on the left until it reaches the designated height
StringBuilder stringBuilder = new StringBuilder(str);
while (stringBuilder.length() < upTo) {
    stringBuilder.insert(0, padding);
return stringBuilder.toString();
StringpadString(String source)
pad String
char paddingChar = ' ';
int size = 16;
int x = source.length() % size;
int padLength = size - x;
for (int i = 0; i < padLength; i++) {
    source += paddingChar;
return source;
...