Java Utililty Methods String Truncate

List of utility methods to do String Truncate

Description

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

Method

Stringtrunc(String in, int len)
This method is used to truncate a string to a specific length.
if (in != null && in.length() > len)
    return in.substring(0, len);
return in;
Stringtrunc(String s, int length)
Takes a string and a length, and truncates it to that that length.
if (s.length() <= length)
    return s;
else
    return s.substring(0, length);
Stringtrunc(String s1, int length)
trunc
if (s1 == null) {
    return "";
if (s1.length() > length && length <= 2) {
    return s1.substring(0, length);
if (s1.length() > length) {
    return s1.substring(0, length - 2) + "..";
...
Stringtrunc(String str, int length)
truncate a String to the desired length
if (str == null)
    str = "Error";
else if (str.length() >= length)
    str = str.substring(0, length);
return str;
Stringtrunc(String string, int length)
Truncates the String by removing characters from the right side of the String so it is length characters long.
int absLength = Math.abs(length);
if ((string == null) || (string.length() <= absLength)) {
    return string;
if (length < 0) {
    int sLength = string.length();
    return string.substring(sLength - absLength, sLength);
return string.substring(0, length);
Stringtrunc(String txt, int size)
trunc
if (txt == null)
    return txt;
else if (txt.length() > size) {
    return txt.substring(0, size - 1);
} else {
    return txt;
Stringtrunc(String value, int len)
trunc
if (len < value.length())
    value = left(value, len);
return value;
Stringtruncate(final String description)
Truncates the input description to maximum 100 character length.
return truncate(description, 100);
Stringtruncate(final String in, final int maxLen)
Truncates string to maxLen.
if (in == null || in.length() <= maxLen) {
    return in;
} else {
    return in.substring(0, maxLen);
Stringtruncate(final String originalString, final int maxChars)
Truncates a string to a given length if it exceeds the length.
if (originalString == null) {
    return null;
if (maxChars < 1) {
    return "";
if (maxChars >= originalString.length()) {
    return originalString;
...