public static String pad(String string,int minLength){
  String result=string;
  int pad=minLength - string.length();
  if (pad > 0) {
    result=string + pad(minLength - string.length());
  }
 else   if (pad < 0) {
    result=string.substring(0,minLength);
  }
  return result;
}

public static String pad ( String string , int minLength ) { String result = string ; int pad = minLength - string . length ( ) ; if ( pad > 0 ) { result = string + pad ( minLength - string . length ( ) ) ; } else if ( pad < 0 ) { result = string . substring ( 0 , minLength ) ; } return result ; }
pads with spaces or truncates the given string to guarantee that it is exactly the desired length .
