Android examples for java.lang:String Pad
Pad a string on the left until it reaches the designated height
import android.text.SpannableString; import android.text.Spanned; import android.text.SpannedString; import android.text.TextUtils; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main{ /**/*from w w w. j ava 2 s .co m*/ * Pad a string on the left until it reaches the designated height * @param str * @param padding * @param upTo * @return */ public static String padLeft(String str, char padding, int upTo) { StringBuilder stringBuilder = new StringBuilder(str); while (stringBuilder.length() < upTo) { stringBuilder.insert(0, padding); } return stringBuilder.toString(); } }