Here you can find the source of leftPadding(String in, int count, char pad)
Parameter | Description |
---|---|
in | String to left pad |
count | Minimum string length to achieve |
pad | Character to pad with |
static String leftPadding(String in, int count, char pad)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from www.ja v a 2 s.c o m*/ * Applies a left padding to the provided string. If the string is already count in length, * no change will be made. Otherwise, the pad character will be prepended until count length * is satisfied. * * @param in String to left pad * @param count Minimum string length to achieve * @param pad Character to pad with * @return String */ static String leftPadding(String in, int count, char pad) { if (in.length() >= count) return in; StringBuilder sb = new StringBuilder(); for (int i = 0; i < count - in.length(); i++) { sb.append(pad); } for (char c : in.toCharArray()) { sb.append(c); } return sb.toString(); } }