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

StringtruncateFirstEnd(String str)
truncate First End
if (isEmpty(str))
    return str;
String tmp = str.substring(1);
return tmp.substring(0, tmp.length() - 1);
inttruncateHashToInt(String hash)
Computes a truncated code from the given hash-value and returns it as int-variable.
return truncateHashToInt(hexToBytes(hash));
StringtruncateIfTooLong(String string, int maxLength)
truncate If Too Long
if (string.length() > maxLength) {
    return string.substring(0, maxLength) + "...";
} else {
    return string;
StringtruncateIgnoreCase(String aString, String trailingSubString)
Return a substring of the first parameter, up to the last index of the second
int index = aString.toLowerCase().lastIndexOf(trailingSubString.toLowerCase());
if (index != -1)
    return aString.substring(0, index);
return aString;
inttruncateInt(String intStr)
truncate Int
int len = intStr.length();
int result = 0;
for (int i = 0; i < len; i++) {
    char c = intStr.charAt(i);
    if (c >= '0' && c <= '9') {
        result = result * 10;
        result += c - '0';
    } else {
...
StringtruncateJavaBeanMethodName(String methodName, int prefixLength)
truncate Java Bean Method Name
if (methodName.length() <= prefixLength) {
    return null;
methodName = methodName.substring(prefixLength);
if (methodName.length() == 1) {
    return methodName.toLowerCase();
char firstChar = methodName.charAt(0);
...
StringtruncateLabel(String label)
Truncates the Specified label to MAX_LENGTH Chars.
String newLabel = label;
if (label.length() > MAX_LENGTH) {
    newLabel = label.substring(0, MAX_LENGTH) + "...";
return newLabel;
StringtruncateLeadingSlash(String uri)
Any leading / in the given uri will be removed.
if (uri == null) {
    return uri;
while (uri.startsWith("/")) {
    uri = uri.substring(1);
return uri;
StringtruncateLongName(String name, int nameLength)
Automatically Truncates Long Names.
if (name != null) {
    if (name.length() > nameLength) {
        name = name.substring(0, nameLength - 3) + "...";
return entityFilter(name);
StringtruncateLongStr(String str)
truncate Long Str
if (str != null) {
    str = str.replaceAll("[\n\r \t]+", " ");
    if (str.length() > MAX_DISPLAY_STRING_LEN) {
        str = str.substring(0, MAX_DISPLAY_STRING_LEN / 2 - 1) + "..."
                + str.substring(str.length() - MAX_DISPLAY_STRING_LEN / 2);
return str;
...