Java tutorial
//package com.java2s; import java.util.Arrays; public class Main { public static String prependString(String str, int len) { try { char[] tmp = new char[len - str.length()]; Arrays.fill(tmp, ' '); return new String(tmp) + str; } catch (Exception e) { e.printStackTrace(); } return str; } }