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