Android examples for java.lang:String Pad
Pad the specified number of spaces to the input string to make it that length
import android.text.TextUtils; import java.util.ArrayList; import java.util.List; public class Main{ /**//from w w w.j av a2s . c o m * Pad the specified number of spaces to the input string to make it that length * @param input * @param size * @return */ public static String padLeft(String input, int size) { if (input.length() > size) { throw new IllegalArgumentException( "input must be shorter than or equal to the number of spaces: " + size); } StringBuilder sb = new StringBuilder(); for (int i = input.length(); i < size; i++) { sb.append(" "); } return sb.append(input).toString(); } }