Java tutorial
//package com.java2s; public class Main { public static final CharSequence padFront(final CharSequence pText, final char pPadChar, final int pLength) { final int padCount = pLength - pText.length(); if (padCount <= 0) { return pText; } else { final StringBuilder sb = new StringBuilder(); for (int i = padCount - 1; i >= 0; i--) { sb.append(pPadChar); } sb.append(pText); return sb.toString(); } } }