Java Number Min Value minimizeWhitespace(String str)

Here you can find the source of minimizeWhitespace(String str)

Description

minimize Whitespace

License

LGPL

Declaration

public static String minimizeWhitespace(String str) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static Object minimizeWhitespace(Object o) {
        return minimizeWhitespace(String.valueOf(o));
    }//from  w  w  w.ja v  a  2 s. c  o m

    public static String minimizeWhitespace(String str) {
        str = str.trim();

        StringBuilder buff = new StringBuilder();
        int len = str.length();
        boolean lastWasNonWhite = true;
        for (int i = 0; i < len; ++i) {
            char c = str.charAt(i);
            if (Character.isWhitespace(c)) {
                if (lastWasNonWhite) {
                    lastWasNonWhite = false;
                    buff.append(' ');
                }
            } else {
                lastWasNonWhite = true;
                buff.append(c);
            }
        }
        return buff.toString();
    }
}

Related

  1. minifyPubkey(String pubkey)
  2. minIgnoreNull(Integer a, Integer b)
  3. minimalIndexOf(String str, String separators, int startIndex)
  4. minimiseSpaces(String input)
  5. minimize(final StringBuilder src)
  6. minimum(float first, float second)
  7. Minimum(float x, float y)
  8. minimum(int a, int b, int c)
  9. Minimum(int a, int b, int c)