Here you can find the source of truncateString(String str, int maxlen)
public static String truncateString(String str, int maxlen)
//package com.java2s; //License from project: Apache License public class Main { public static String truncateString(String str, int maxlen) { return truncateString(str, maxlen, false); }// w ww . j a v a 2s. c om public static String truncateString(String str, int maxlen, boolean elipsis) { if (str == null) return ""; if (elipsis) maxlen -= 3; if (str.length() > maxlen) str = str.substring(0, maxlen); if (elipsis) return str + "..."; else return str; } }