Left padding : String Pad « Data Type « Java






Left padding

   

public class Util{
  /**
   * @param src
   * @param length
   * @param padding
   * @return
   */
  public static String lpad(String src, int length, char padding)
  {
    if(src == null)
    {
      src = "";
    }

    while(src.length() < length)
    {
      src = padding + src;
    }
    
    return src;
  }

}

   
    
    
  








Related examples in the same category

1.Left pad a String with a specified String.
2.Left pad a String with a specified character.
3.Left pad a String with spaces (' ').
4.Right pad a String with a specified String.
5.Right pad a String with a specified character.
6.Right pad a String with spaces (' ').
7.Padding and triming strings
8.Pad string
9.Padded String
10.Set string length, padding with character if the shorter, or truncating if longer
11.Returns the quoted version of the string using the quotechar argument.
12.Return a string padded with the given string for the given count.
13.Left pad the given text parameter
14.Right pad the given text parameter
15.Right padding
16.Pads the string with 0x and zeros on the left until it has the requested size.
17.Pads the string with zeros on the left until it has the requested size.
18.Right, left justify the string