Here you can find the source of padLeft(String input, int size)
Parameter | Description |
---|---|
input | a parameter |
size | a parameter |
public static String padLeft(String input, int size)
//package com.java2s; public class Main { /**//w w w . ja v 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(); } }