Here you can find the source of abbreviateMiddle(String string, int maxLength)
public static String abbreviateMiddle(String string, int maxLength)
//package com.java2s; public class Main { public static final String ELLIPSIS = "..."; public static String abbreviateMiddle(String string, int maxLength) { if (string == null || maxLength >= string.length()) { return string; }//from w w w . j a v a2 s . co m final int targetSting = maxLength - ELLIPSIS.length(); final int startOffset = targetSting / 2 + targetSting % 2; final int endOffset = string.length() - targetSting / 2; return string.substring(0, startOffset) + ELLIPSIS + string.substring(endOffset); } }