Here you can find the source of truncateByCharLengthWithEllipsis(String string, int maxLength)
public static String truncateByCharLengthWithEllipsis(String string, int maxLength)
//package com.java2s; //License from project: Open Source License public class Main { public static String truncateByCharLengthWithEllipsis(String string, int maxLength) { return string.length() <= maxLength ? string : truncateByCharLength(string, maxLength - 3) + "..."; }/*from w w w . j a v a2 s .c o m*/ public static String truncateByCharLength(String string, int maxLength) { return string.length() > maxLength ? string.substring(0, maxLength) : string; } }