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 str, int maximumChars)

Abbreviates the specified String if its length exceeds the value specified by maximumChars.

if (!isEmpty(str)) {
    if (str.length() > maximumChars) {
        return (str.substring(0, maximumChars) + "...");
return (str);
Stringabbreviate(String str, int maxlen, String appendIfLimit)
Return abbreviated string to maxlen length.
if (appendIfLimit == null)
    appendIfLimit = "";
if (str.length() > maxlen) {
    return str.substring(0, maxlen - appendIfLimit.length()) + appendIfLimit;
return str;
Stringabbreviate(String str, int maxWidth)
Abbreviates a string to a specified length and then adds an ellipsis if the input is greater than the maxWidth.
if (null == str) {
    return null;
if (str.length() <= maxWidth) {
    return str;
return str.substring(0, maxWidth) + "...";
Stringabbreviate(String str, int maxWidth)
abbreviate
if (null == str)
    return null;
if (str.length() <= maxWidth)
    return str;
else
    return (new StringBuilder()).append(chopAtWord(str, maxWidth)).append("...").toString();
Stringabbreviate(String str, int maxWidth)

Abbreviates a String using ellipses.

return abbreviate(str, 0, maxWidth);
Stringabbreviate(String str, int maxWidth)
abbreviate
if (str == null)
    return null;
if (maxWidth < 4)
    throw new IllegalArgumentException("Minimum abbreviation width is 4");
return str.substring(0, maxWidth - 3) + "...";
Stringabbreviate(String str, int maxWidth)
Abbreviates a String using ellipses.
if (str == null) {
    return null;
if (str.length() < maxWidth) {
    return str;
if (maxWidth < 4) {
    throw new IllegalArgumentException("Minimum required width is 4");
...
Stringabbreviate(String str, int maxWidth)
Abbreviates a string to a specified length and then adds an ellipsis if the input is greater than the maxWidth.
if (null == str) {
    return null;
if (str.length() <= maxWidth) {
    return str;
return str.substring(0, maxWidth) + "...";
Stringabbreviate(String str, int maxWidth)
abbreviate
if (isBlank(str)) {
    return str;
if (str.length() <= maxWidth) {
    return str;
if (maxWidth < 3) {
    throw new IllegalArgumentException("maxWidth must be >= 3");
...
Stringabbreviate(String str, int maxWidth)
abbreviate
return abbreviate(str, 0, maxWidth);