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

Stringtruncate(String text, int size, String charsetName)
truncate
return truncate(text, 0, size, charsetName, 3);
Stringtruncate(String text, int truncatedLength)
Truncate a string to a max length
if (text == null) {
    return null;
if ((truncatedLength < 0) || (truncatedLength > text.length())) {
    return text;
return text.substring(0, truncatedLength);
Stringtruncate(String toTruncate, int maxSize)
Truncate the given string to a maximum length provided with a pad (...) added to the end if expected size if more than 10.
if (toTruncate == null || maxSize < 1 || toTruncate.length() <= maxSize) {
    return toTruncate;
String pad = "...";
if (maxSize < 10) {
    pad = "";
return toTruncate.substring(0, maxSize - pad.length()).concat(pad);
...
Stringtruncate(String url, int offset, int size)
truncate
return url.substring(offset, offset + size - 3) + "...";
StringTruncate(String v, int length)
Truncate
return v.substring(0, Math.min(v.length(), length));
Stringtruncate(String val, int maxlen)
truncate
return val.length() > maxlen ? (val.substring(0, maxlen - 2) + "..") : val;
Stringtruncate(String value, int length)
truncate
return truncate(value, 0, length);
Stringtruncate(String value, int length)
truncate
if (value != null && value.length() > length) {
    value = value.substring(0, length);
    value += "...";
return value;
Stringtruncate(String value, int length)
Truncates a String to the given length.
if (value != null && value.length() > length) {
    value = value.substring(0, length);
    value += DOTS;
return value;
Stringtruncate(String value, int length)
Truncate the given string
if (value != null && value.length() > length)
    value = value.substring(0, length);
return value;