2016-04-21 49 views

回答

3

實現你自己PadLeft

public static String padLeft(String value, int width, char pad) { 
    if (value.length() >= width) 
     return value; 
    char[] buf = new char[width]; 
    int padLen = width - value.length(); 
    Arrays.fill(buf, 0, padLen, pad); 
    value.getChars(0, value.length(), buf, padLen); 
    return new String(buf); 
} 

IDEONE demo