Here you can find the source of shorten(String s)
public static String shorten(String s)
//package com.java2s; //License from project: Open Source License public class Main { public static String shorten(String s) { return shorten(s, 20); }//from www. j ava 2 s . c om public static String shorten(String s, int length) { return shorten(s, length, "..."); } public static String shorten(String s, int length, String suffix) { if ((s == null) || (suffix == null)) { return null; } if (s.length() > length) { for (int j = length; j >= 0; j--) { if (Character.isWhitespace(s.charAt(j))) { length = j; break; } } String temp = s.substring(0, length); s = temp.concat(suffix); } return s; } public static int length(String s) { if (s == null) { return 0; } return s.length(); } }