Here you can find the source of rightPad(String in, char padding, int length)
public static String rightPad(String in, char padding, int length)
//package com.java2s; /*/*www . ja va 2s .com*/ GPON General Purpose Object Network Copyright (C) 2006 Daniel Schulz This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ public class Main { public static String rightPad(String in, char padding, int length) { String out = ""; int toPad = length - in.length(); if (toPad < 0) { throw new IllegalArgumentException("Input string longer than requested length"); } out = in + getStringRepetition(padding + "", toPad); return out; } public static String getStringRepetition(String in, int times) { StringBuffer out = new StringBuffer(""); for (int i = 0; i < times; i++) { out = out.append(in); } return out.toString(); } }