Here you can find the source of trunc(String str, int length)
private static String trunc(String str, int length)
//package com.java2s; public class Main { /**// w w w .j a v a 2s .c om * truncate a String to the desired length */ private static String trunc(String str, int length) { if (str == null) str = "Error"; else if (str.length() >= length) str = str.substring(0, length); return str; } }