Here you can find the source of shorten(String str, int length)
public static String shorten(String str, int length)
//package com.java2s; //License from project: Open Source License public class Main { public static String shorten(String str, int length) { if (str.length() <= length) return str; return str.substring(0, length - 3) + "..."; }/*from w w w. j a va2s . c o m*/ }