Here you can find the source of shortenTo(String string, int lenght)
public static String shortenTo(String string, int lenght)
//package com.java2s; //License from project: Open Source License public class Main { public static String shortenTo(String string, int lenght) { if (string.length() > lenght) { string = string.substring(0, lenght - 4) + " ..."; }//from w ww .ja v a2 s. c o m return string; } }