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

Stringabbr(String str, int length)
abbr
if (str == null) {
    return "";
try {
    StringBuilder sb = new StringBuilder();
    int currentLength = 0;
    for (char c : str.toCharArray()) {
        currentLength += String.valueOf(c).getBytes("GBK").length;
...
Stringabbrev(String longString, int size)
Returns the first size characters of the given string.
return longString.length() <= size ? longString : longString.substring(0, size);
Stringabbrev(String result, int maxLength, String separator)
Make sure a string stays within a certain length, by cutting a bit from the middle.
int mid = maxLength / 2;
if (result.length() > maxLength)
    result = result.substring(0, mid - 1) + separator + result.substring(result.length() - mid);
return result;
Stringabbreviate(final String str)
abbreviate
return abbreviate(str, DEFAULT_ABBREVIATE_MAX_WIDTH);
Stringabbreviate(final String str, final int maxWidth)
abbreviate
return str != null && str.length() > maxWidth ? str.substring(0, maxWidth - 3) + "..." : str;
Stringabbreviate(final String str, int lower, int upper, final String appendToEnd)
see WordUtils#abbreviate.
if (str == null) {
    return null;
if (str.length() == 0) {
    return "";
if (lower > str.length()) {
    lower = str.length();
...
Stringabbreviate(final String value, final int maxLength)
abbreviate
assert maxLength > 4;
if (value.length() > maxLength) {
    return value.substring(0, maxLength - 3) + "...";
} else {
    return value;
Stringabbreviate(final String value, int max)
Abbreviates the given value to max characters (if necessary).
If the value is abbreviated, the result ends with " ...
if (value == null) {
    return null;
if (max < 0) {
    max = 0;
return value.length() > max ? value.substring(0, max) + "..." : value;
Stringabbreviate(String _str, int _length)
Abbreviates a String using ellipses.
if (_str == null) {
    return null;
if (_str.length() <= _length) {
    return _str;
String abbr = _str.substring(0, _length - 3) + "...";
return abbr;
...
Stringabbreviate(String content, int maxWidth, String enc, String suffix)
abbreviate
if (content == null)
    return "";
if (maxWidth < suffix.length())
    throw new IllegalArgumentException();
int ptr = maxWidth - suffix.length();
String str = null;
try {
    byte bytes[] = content.getBytes(enc);
...