Here you can find the source of rightPad(String toPad, int totalLength)
public static String rightPad(String toPad, int totalLength)
//package com.java2s; //License from project: Open Source License public class Main { public static String rightPad(String toPad, int totalLength) { if (toPad == null) return null; if (toPad.length() >= totalLength) { return toPad.substring(0, totalLength); }// w w w . j a v a 2 s .c om StringBuffer buf = new StringBuffer(toPad); while (buf.length() < totalLength) { buf.append(" "); } return buf.toString(); } }