public static String trimLength(String str,int length){
  if (str == null)   return str;
  if (length <= 0)   throw new IllegalArgumentException("Trim length invalid: " + length);
  if (str.length() > length)   return str.substring(0,length);
  return str;
}

public static String trimLength ( String str , int length ) { if ( str == null ) return str ; if ( length <= 0 ) throw new IllegalArgumentException ( "Trim length invalid: " + length ) ; if ( str . length ( ) > length ) return str . substring ( 0 , length ) ; return str ; }
trim to max character length
