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

charcollapse(char c)
collapse
if (c >= diacritics.length) {
    return c;
char tc = diacritics[c];
return (tc == 0) ? c : tc;
doublecollapse(double[] w)
collapse
if (w == null) {
    return 0.0;
double summ = 0.0d;
for (int i = 0; i < w.length; i++) {
    summ += w[i];
return summ;
...
float[]collapse(float[][] array)
Collapse a two-dimensional array to a one-dimensional one
float[] a = new float[array[0].length * array.length];
int i = 0;
for (int x = 0; x < array.length; x++) {
    for (int y = 0; y < array[x].length; y++) {
        a[i++] = array[x][y];
return a;
...
Stringcollapse(String str, String characters, String replacement)
collapse
if (str == null) {
    return null;
StringBuffer newStr = new StringBuffer();
boolean prevCharMatched = false;
char c;
for (int i = 0; i < str.length(); i++) {
    c = str.charAt(i);
...
Stringcollapse(String t)
collapse
for (int i = 0, length = t.length(); i < length; i++)
    if (!Character.isWhitespace(t.charAt(i)))
        for (int j = length - 1; j >= i; j--)
            if (!Character.isWhitespace(t.charAt(j)))
                return (i > 0 ? " " : "") + t.substring(i, j + 1) + (j < length - 1 ? " " : "");
return "";
Stringcollapse(String text)
Collapses whitespace
int len = text.length();
int s = 0;
while (s < len) {
    if (isWhiteSpace(text.charAt(s)))
        break;
    s++;
if (s == len)
...
StringcollapsedName(Class klass)
collapsed Name
String name = klass.getName();
if (name.startsWith(PREFIX_RESOURCES)) {
    return SHORT_RESOURCES + name.substring(PREFIX_RESOURCES.length());
if (name.startsWith(PREFIX)) {
    return SHORT + name.substring(PREFIX.length());
return name;
...
StringcollapseLines(String message)
Returns a string with all break lines replaced by the string "\n"
return message.replaceAll("\n", "\\\\n");
StringcollapseMultipleNewlinesToOne(String s)
collapse Multiple Newlines To One
return s.replaceAll("\\\n+", "\\\n");
StringcollapseName(String name)
Collapse primitive type names.
if (name.equals("unsigned short"))
    name = "ushort";
else if (name.equals("unsigned long"))
    name = "ulong";
else if (name.equals("unsigned long long"))
    name = "ulonglong";
else if (name.equals("long long"))
    name = "longlong";
...