public static String padLeft(String str,int totalChars){
  if (str == null)   str="null";
  StringBuilder sb=new StringBuilder();
  for (int i=0; i < totalChars - str.length(); i++) {
    sb.append(" ");
  }
  sb.append(str);
  return sb.toString();
}

public static String padLeft ( String str , int totalChars ) { if ( str == null ) str = "null" ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < totalChars - str . length ( ) ; i ++ ) { sb . append ( " " ) ; } sb . append ( str ) ; return sb . toString ( ) ; }
pads the given string to the left with spaces to ensure that it ' s at least totalchars long .
