Here you can find the source of leftJustify(long v, int width)
leftJustify()
method pads a string to a specified length by adding spaces on the right, thus justifying the string to the left margin.
Parameter | Description |
---|---|
v | a long value to convert to a string and justify |
width | the number of characters to pad the string to |
public static String leftJustify(long v, int width)
//package com.java2s; public class Main { /**//w ww. java 2s . com * The <code>leftJustify()</code> method pads a string to a specified length by adding spaces on the * right, thus justifying the string to the left margin. This is extremely useful in generating columnar * output in textual tables. * * @param v a long value to convert to a string and justify * @param width the number of characters to pad the string to * @return a string representation of the input, padded on the right with spaces to achieve the desired * length. */ public static String leftJustify(long v, int width) { return leftJustify(Long.toString(v), width); } /** * The <code>leftJustify()</code> method pads a string to a specified length by adding spaces on the * right, thus justifying the string to the left margin. This is extremely useful in generating columnar * output in textual tables. * * @param v a floating point value to convert to a string and justify * @param width the number of characters to pad the string to * @return a string representation of the input, padded on the right with spaces to achieve the desired * length. */ public static String leftJustify(float v, int width) { return leftJustify(Float.toString(v), width); } /** * The <code>leftJustify()</code> method pads a string to a specified length by adding spaces on the * right, thus justifying the string to the left margin. This is extremely useful in generating columnar * output in textual tables. * * @param s a string to justify * @param width the number of characters to pad the string to * @return a string representation of the input, padded on the right with spaces to achieve the desired * length. */ public static String leftJustify(String s, int width) { StringBuffer buf = new StringBuffer(s); for (int pad = width - s.length(); pad > 0; pad--) buf.append(' '); return buf.toString(); } }