Here you can find the source of clamp(String string, int maxChars)
public static String clamp(String string, int maxChars)
//package com.java2s; public class Main { public static String clamp(String string, int maxChars) { if (containsData(string) && string.length() > maxChars) { string = string.substring(0, maxChars) + "..."; }//ww w . j ava 2 s . c o m return string; } /** * Test is the given String is not NULL and if it contains more then one character. * * @param string * @return */ public static boolean containsData(String string) { if (string == null) { return false; } return string.length() > 0; } }