public static String truncateString(String str,int len){
  return str.substring(0,Math.min(len,str.length()));
}

public static String truncateString ( String str , int len ) { return str . substring ( 0 , Math . min ( len , str . length ( ) ) ) ; }
truncates a string to a desired maximum length . like string . substring ( int , int ) , but throw no exception if desired length is longer than the string .
