Here you can find the source of truncate(String str, int max)
public static String truncate(String str, int max)
//package com.java2s; public class Main { public static String truncate(String str, int max) { if (str.length() <= max) { return str; }// ww w . java 2 s. c o m return str.substring(0, max); } }