Here you can find the source of rightPad(String field, char padding, int width)
public static String rightPad(String field, char padding, int width)
//package com.java2s; public class Main { public static String rightPad(String field, char padding, int width) { String answer;/*from www.ja v a 2 s.c o m*/ if (field.length() < width) { answer = field + fill(padding, width - field.length()); } else { answer = field; } return answer; } public static String fill(final char c, final int n) { StringBuffer answer = new StringBuffer(n); fill(answer, c, n); return answer.toString(); } public static void fill(StringBuffer buf, final char c, final int n) { for (int i = 0; i < n; i++) { buf.append(c); } } }