Here you can find the source of rightPad(String string, int length)
public static String rightPad(String string, int length)
//package com.java2s; //License from project: Open Source License public class Main { public static String rightPad(String string, int length) { return rightPad(string, length, ' '); }//from www . j a va2 s .co m public static String rightPad(String string, int length, char ch) { if (string == null || string.length() >= length) return string; StringBuffer sb = new StringBuffer(string); for (int i = (string.length() - 1); i < length - 1; i++) sb.append(ch); return sb.toString(); } }