Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String limitLenOfStr(String str, int maxLen) { if (null != str && str.length() > maxLen) { StringBuffer sb = new StringBuffer(); sb.append(str.substring(0, maxLen)); sb.append("..."); return sb.toString(); } return str; } }