Here you can find the source of alignRight(String val, char pad, int width)
public static String alignRight(String val, char pad, int width)
//package com.java2s; /* ************************************************************************ # # DivConq//from www . j a v a2 s. c om # # http://divconq.com/ # # Copyright: # Copyright 2014 eTimeline, LLC. All rights reserved. # # License: # See the license.txt file in the project's top-level directory for details. # # Authors: # * Andy White # ************************************************************************ */ public class Main { public static String alignRight(String val, char pad, int width) { if (val.length() > width) { val = val.substring(0, width - 1) + "*"; return val; } while (val.length() < width) val = pad + val; return val; } /** * Gets a CharSequence length or {@code 0} if the CharSequence is * {@code null}. * * @param cs * a CharSequence or {@code null} * @return CharSequence length or {@code 0} if the CharSequence is * {@code null}. * @since 2.4 * @since 3.0 Changed signature from length(String) to length(CharSequence) */ public static int length(final CharSequence cs) { return cs == null ? 0 : cs.length(); } }