Here you can find the source of lpad(String s, int len, char ch)
Parameter | Description |
---|---|
s | the string. |
len | the desired length. |
ch | the character used for padding |
public static String lpad(String s, int len, char ch)
//package com.java2s; public class Main { /**/*from www . j a v a 2 s . co m*/ * Pads a string to the desired length. * @param s the string. * @param len the desired length. * @param ch the character used for padding * @return the padded string. */ public static String lpad(String s, int len, char ch) { if (s == null || s.length() >= len) return s; StringBuffer buf = new StringBuffer(len); for (len -= s.length(); len > 0; len--) buf.append(ch); buf.append(s); return buf.toString(); } }