public static String enlargeString(String string,int minimalTextLength){
  if (string == null || string.isEmpty()) {
    throw new IllegalArgumentException("No string given");
  }
  if (minimalTextLength < 0) {
    throw new IllegalArgumentException("Number of blanks has to be positive");
  }
  int n=minimalTextLength - string.length();
  if (n <= 0) {
    return string;
  }
  int nrSpaces=(int)Math.ceil(n / 2.0);
  String spaces=String.format("%" + nrSpaces + "s","");
  return spaces + string + spaces;
}

public static String enlargeString ( String string , int minimalTextLength ) { if ( string == null || string . isEmpty ( ) ) { throw new IllegalArgumentException ( "No string given" ) ; } if ( minimalTextLength < 0 ) { throw new IllegalArgumentException ( "Number of blanks has to be positive" ) ; } int n = minimalTextLength - string . length ( ) ; if ( n <= 0 ) { return string ; } int nrSpaces = ( int ) Math . ceil ( n / 2.0 ) ; String spaces = String . format ( "%" + nrSpaces + "s" , "" ) ; return spaces + string + spaces ; }
returns enlarged string , with a suffix and a prefix of blanks to reach the given minimal text length example : enlargestring ( " 1234 " , 8 ) - > " 1234 "
