Here you can find the source of format(int i, int fillLength)
public static String format(int i, int fillLength)
//package com.java2s; public class Main { public static final int ALIGN_RIGHT = 0; public static final int ALIGN_LEFT = 1; private static final char defaultSplitChar = ' '; public static String format(String s, int fillLength) { return format(s, fillLength, defaultSplitChar, ALIGN_LEFT); }/*from w ww. j a v a 2 s .co m*/ public static String format(int i, int fillLength) { return format(Integer.toString(i), fillLength, defaultSplitChar, ALIGN_RIGHT); } public static String format(long l, int fillLength) { return format(Long.toString(l), fillLength, defaultSplitChar, ALIGN_RIGHT); } public static String format(String s, int fillLength, char fillChar, int align) { if (s == null) { s = ""; } else { s = s.trim(); } int charLen = fillLength - s.length(); if (charLen > 0) { char[] fills = new char[charLen]; for (int i = 0; i < charLen; i++) { fills[i] = fillChar; } StringBuilder str = new StringBuilder(s); switch (align) { case ALIGN_RIGHT: str.insert(0, fills); break; case ALIGN_LEFT: str.append(fills); break; default: str.append(fills); } return str.toString(); } else { return s; } } }