Here you can find the source of rightPad(String csIn, int nRequiredLength, char cFill)
public static String rightPad(String csIn, int nRequiredLength, char cFill)
//package com.java2s; /*//from w w w . j a v a2s.c o m * JLib - Publicitas Java library v1.2.0. * * Copyright (c) 2005, 2006, 2007, 2008, 2009 Publicitas SA. * Licensed under LGPL (LGPL-LICENSE.txt) license. */ public class Main { public static String rightPad(String csIn, int nRequiredLength, char cFill) { String csOut = new String(); int nLgStringIn = csIn.length(); int nNbcharToPad = nRequiredLength - nLgStringIn; if (nNbcharToPad > 0) { csOut = csIn; for (int n = 0; n < nNbcharToPad; n++) { csOut = csOut + cFill; } } else // Keep only leftmost chars { csOut = csIn.substring(0, nRequiredLength); } return csOut; } }