Java Utililty Methods String Abbreviate

List of utility methods to do String Abbreviate

Description

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

Method

Stringabbreviate(String fileName, int maxLen)
Abbreviates a path name by replacing sub directories by an ellipsis character.
if (fileName.length() <= maxLen)
    return fileName;
File f = new File(fileName);
ArrayList<String> coll = new ArrayList<String>();
String name;
StringBuffer begBuf = new StringBuffer();
StringBuffer endBuf = new StringBuffer();
int len;
...
Stringabbreviate(String input, int length)

Abbreviates a string to a desired length and adds "..."

if (input == null) {
    return null;
if (input.length() <= length) {
    return input;
return input.substring(0, length) + "...";
Stringabbreviate(String longName)
Abbreviate a string.
if (longName == null) {
    return "<Unnamed>";
if (longName.length() <= 80) {
    return longName;
return longName.substring(0, 37) + ". . ." + longName.substring(longName.length() - 38);
Stringabbreviate(String longStr, int maxLength)
abbreviate
String _longStr = getEmptyIfNull(longStr);
return _longStr.length() > maxLength ? _longStr.substring(0, maxLength - 2) + ".." : _longStr;
Stringabbreviate(String name)
abbreviate
StringBuilder newName = new StringBuilder(name);
if (name.length() > 14) {
    for (int i = 0; i < (name.length() - 12); i++) {
        newName.deleteCharAt(newName.length() - 1);
    newName.append("..");
    return newName.toString();
return name;
Stringabbreviate(String s, int length)
abbreviate
if (s == null)
    return null;
if (s.length() <= length)
    return s;
s = s.substring(0, length - 5);
if (s.endsWith(" ")) {
    s += "...";
} else {
...
Stringabbreviate(String s, int max)
Turn "Now is the time for all good men" into "Now is the time for..."
if (max < 4)
    throw new IllegalArgumentException("Minimum abbreviation is 3 chars");
if (s.length() <= max)
    return s;
return s.substring(0, max - 3) + "...";
Stringabbreviate(String s, int maxLength)
abbreviate
s = String.valueOf(s); 
if (s.length() > maxLength) {
    s = s.substring(0, maxLength) + "...";
return s;
Stringabbreviate(String src, int maxlen, String replacement)
abbreviate
if (src == null)
    return "";
if (replacement == null) {
    replacement = "";
StringBuffer dest = new StringBuffer();
try {
    maxlen = maxlen - computeDisplayLen(replacement);
...
Stringabbreviate(String str)
Abbreviates a string such that it doesn't straddle more than one line, and isn't very long.
return abbreviate(str, 60);