Here you can find the source of leftPad(String string, char pad, int size)
Parameter | Description |
---|---|
string | a parameter |
pad | a parameter |
size | a parameter |
public static String leftPad(String string, char pad, int size)
//package com.java2s; public class Main { /**/*w ww . j av a2 s . c om*/ * Return the padded left of a string by padding character. * * @param string * @param pad * @param size * @return */ public static String leftPad(String string, char pad, int size) { if (string == null || size < 0) { return null; } else if (string.length() == 0 || size == 0) { return ""; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < size; i++) { sb.append(pad); } sb.append(string); int lengthOfInterimString = sb.length(); return sb.toString().substring(lengthOfInterimString - size, lengthOfInterimString); } }