Java tutorial
//package com.java2s; public class Main { public static String trimText(String str, int length) { if (!isNullOrEmpty(str)) { if (str.length() > length) { str = str.substring(0, length - 1); str += "..."; } } return str; } public static boolean isNullOrEmpty(String str) { if (str == null || str.trim().equals("")) { return true; } return false; } }