Java Utililty Methods String Collapse

List of utility methods to do String Collapse

Description

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

Method

StringcollapseNewlines(String argStr)
Remove/collapse multiple newline characters.
char last = argStr.charAt(0);
StringBuffer argBuf = new StringBuffer();
for (int cIdx = 0; cIdx < argStr.length(); cIdx++) {
    char ch = argStr.charAt(cIdx);
    if (ch != '\n' || last != '\n') {
        argBuf.append(ch);
        last = ch;
return argBuf.toString();
StringcollapseString(String data, String collapse)
Collapse a String from an input String.
if (data == null || collapse == null)
    return null;
StringBuffer t1;
int pos = data.indexOf(collapse);
if (pos == -1)
    return data;
t1 = new StringBuffer();
int start = 0;
...
voidcollapseStrings(String[] strings)
Empty out all but the smallest unique strings from the array.
if (strings == null || strings.length < 2)
    return;
for (int i = 0; i < strings.length - 1; ++i) {
    final String string1 = strings[i];
    if (string1 == null)
        continue;
    final int len1 = string1.length();
    for (int j = i + 1; j < strings.length; ++j) {
...