Here you can find the source of addEllipsis(String src, String ellipsis, int maxLength)
public static String addEllipsis(String src, String ellipsis, int maxLength)
//package com.java2s; public class Main { public static String addEllipsis(String src, String ellipsis, int maxLength) { if (maxLength < 0) { throw new IllegalArgumentException( "maxLength could not less than zero"); }//from w w w. j av a 2 s. co m int srcLength = src.length(); if (srcLength <= maxLength) { return src; } int ellipsisLength = ellipsis.length(); int dis = srcLength + ellipsisLength - maxLength; if (dis < srcLength) { return src.substring(0, srcLength - dis) + ellipsis; } return ellipsis.substring(dis - srcLength); } }