Here you can find the source of shortenStringIfNecessary(String string, int maxLength, String suffixToAppend)
public static String shortenStringIfNecessary(String string, int maxLength, String suffixToAppend)
//package com.java2s; public class Main { public static final String ELLIPSIS = "..."; public static String shortenStringIfNecessary(String string, int maxLength, String suffixToAppend) { if (string == null) return null; // FIXME: throw IllegalState or log a warning ? return (string.length() > maxLength) ? string.substring(0, maxLength) + suffixToAppend : string; }/* w w w.ja va 2 s. co m*/ public static String shortenStringIfNecessary(String string, int maxLength) { return shortenStringIfNecessary(string, maxLength, ELLIPSIS); } }