Here you can find the source of rightPad(String ret, int limit)
Parameter | Description |
---|---|
ret | The string to pad |
limit | The desired length of the padded string. |
public static final String rightPad(String ret, int limit)
//package com.java2s; //License from project: Apache License public class Main { /**//from w ww .j a va 2 s . com * Right pad a string: adds spaces to a string until a certain length. If * the length is smaller then the limit specified, the String is truncated. * * @param ret * The string to pad * @param limit * The desired length of the padded string. * @return The padded String. */ public static final String rightPad(String ret, int limit) { if (ret == null) return rightPad(new StringBuffer(), limit); else return rightPad(new StringBuffer(ret), limit); } /** * Right pad a StringBuffer: adds spaces to a string until a certain length. * If the length is smaller then the limit specified, the String is * truncated. * * @param ret * The StringBuffer to pad * @param limit * The desired length of the padded string. * @return The padded String. */ public static final String rightPad(StringBuffer ret, int limit) { int len = ret.length(); int l; if (len > limit) { ret.setLength(limit); } else { for (l = len; l < limit; l++) ret.append(' '); } return ret.toString(); } }