Java Utililty Methods String Shorten

List of utility methods to do String Shorten

Description

The list of methods to do String Shorten are organized into topic(s).

Method

byte[]shorten(byte[] array, int length)
shorten
if (length == array.length) {
    return array;
byte[] result = new byte[length];
System.arraycopy(array, 0, result, 0, length);
return result;
Stringshorten(String className)
shorten
String[] split = className.split("\\.");
StringBuilder sb = new StringBuilder();
sb.append(split[split.length - 1]);
return sb.toString();
Stringshorten(String className)
Return the short form of this name, i.e.
if (className == null)
    return null;
int lastDot = className.lastIndexOf(".");
int lastDollar = className.lastIndexOf("$");
int last = max(lastDot, lastDollar);
String shortName = className.substring(last + 1);
return className.charAt(0) == '@' ? "@" + shortName : shortName;
Stringshorten(String clazz)
shorten
if (null != clazz && clazz.endsWith(";")) {
    clazz = clazz.substring(0, clazz.length() - 1);
if (null != clazz && clazz.lastIndexOf(".") > -1) {
    clazz = clazz.substring(clazz.lastIndexOf(".") + 1, clazz.length());
return clazz;
Stringshorten(String fullClassName)
shorten
return fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
Stringshorten(String in)
shorten given string (typically, a filename) by replacing the characters in the middle of the string with dots.
return shorten(in, 32, "...");
Stringshorten(String input)
Shorten text to a character limit
if (140 > input.length()) {
    return input;
int charIndex;
StringBuffer shortenedInput = new StringBuffer();
for (charIndex = 0; charIndex < input.length(); charIndex++) {
    shortenedInput.append(input.charAt(charIndex));
    if (139 == charIndex) {
...
Stringshorten(String input, int length, boolean wholeWord)
Shortens the given text to be as long as the given length (including the appended ellipsis).
if (input == null) {
    return EMPTY;
if (length <= HORIZONTAL_ELLIPSIS.length()) {
    throw new IllegalArgumentException("Length must at least " + HORIZONTAL_ELLIPSIS.length() + 1);
if (input.length() <= length) {
    return input;
...
Stringshorten(String label, int maxLength)
Shortens the given label to the given maximum length and filters non-printable characters.
if (label == null) {
    return null;
if (maxLength < 3) {
    return DOT_DOT_DOT;
if (label.length() > maxLength) {
    label = label.substring(0, maxLength / 2) + DOT_DOT_DOT
...
Stringshorten(String line)
Removes the first and last character of the string.
line = line.trim();
return (line.substring(1, line.length() - 1).trim());