1. padStart
public static String padStart(String string, int minLength, char padChar) {
checkNotNull(string); // eager for GWT.
if (string.length() >= minLength) {
return string;
}
StringBuilder sb = new StringBuilder(minLength);
for (int i = string.length(); i < minLength; i++) {
sb.append(padChar);
}
sb.append(string);
return sb.toString();
}
2. 아 귀찮다 http://www.leveluplunch.com/java/examples/left-pad-string/
3, 뭔가 정리하고 싶은데 귀찮네
String seqNumber = Strings.padStart(Integer.toString(seq), SEQ_LENGTH, '0');
//seqNumber = String.format("%10d", seq).replace(" ", "0");
//seqNumber = StringUtils.leftPad(Integer.toString(seq), SEQ_LENGTH, '0');
4. leftPad
public static String leftPad(final String str, final int size, final char padChar) {
if (str == null) {
return null;
}
final int pads = size - str.length();
if (pads <= 0) {
return str; // returns original String when possible
}
if (pads > PAD_LIMIT) {
return leftPad(str, size, String.valueOf(padChar));
}
return repeat(padChar, pads).concat(str);
}
public static String repeat(final char ch, final int repeat) {
final char[] buf = new char[repeat];
for (int i = repeat - 1; i >= 0; i--) {
buf[i] = ch;
}
return new String(buf);
}