Here you can find the source of alignRight(CharSequence cs, int width, char c)
public static String alignRight(CharSequence cs, int width, char c)
//package com.java2s; //License from project: Apache License public class Main { public static String alignRight(CharSequence cs, int width, char c) { if (null == cs) return null; int len = cs.length(); if (len >= width) return cs.toString(); return new StringBuilder().append(dup(c, width - len)).append(cs).toString(); }// w w w . j a v a 2 s.c o m 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; } }