public static String truncate(String string,int length){
  if (string.length() > length) {
    string=string.substring(0,length);
  }
  return string;
}

public static String truncate ( String string , int length ) { if ( string . length ( ) > length ) { string = string . substring ( 0 , length ) ; } return string ; }
sets the maximum length of the string . longer strings will be simply truncated .
