Here you can find the source of alignLeft(CharSequence cs, int width, char c)
public static String alignLeft(CharSequence cs, int width, char c)
//package com.java2s; //License from project: Apache License public class Main { public static String alignLeft(CharSequence cs, int width, char c) { if (null == cs) return null; int length = cs.length(); if (length >= width) return cs.toString(); return new StringBuilder().append(cs).append(dup(c, width - length)).toString(); }// w ww. ja v a2 s . c om public static String dup(CharSequence cs, int num) { if (isEmpty(cs) || num <= 0) return ""; StringBuilder sb = new StringBuilder(cs.length() * num); for (int i = 0; i < num; i++) sb.append(cs); return sb.toString(); } public static String dup(char c, int num) { if (c == 0 || num < 1) return ""; StringBuilder sb = new StringBuilder(num); for (int i = 0; i < num; i++) sb.append(c); return sb.toString(); } public static boolean isEmpty(CharSequence cs) { return null == cs || cs.length() == 0; } }