public static String center(String s, int length) {
      if (s == null) {
         return null;
      }
      int start = (int) Math.floor(Math.max(0, (length - s.length()) / 2d));
      return padEnd(repeat(' ', start) + s, length, ' ');
   }
public static String center ( String s , int length ) { if ( s == null ) { return null ; } int start = ( int ) Math . floor ( Math . max ( 0 , ( length - s . length ( ) ) / 2d ) ) ; return padEnd ( repeat ( ' ' , start ) + s , length , ' ' ) ; }
Center string.

@param s      the s
@param length the length
@return the string