Here you can find the source of shorten(String text, int max)
public static String shorten(String text, int max)
//package com.java2s; //License from project: Apache License public class Main { public static String shorten(String text, int max) { // case 1: nothing if (text == null) return ""; // case 2: it fits if (text.length() <= max) return text; // case 3: max is short, return what we can if (max <= 5) return text.substring(0, max); // case 4: max is long, return what we can and append .. return text.substring(0, max - 2) + ".."; }/*w ww.j av a2s . c o m*/ }