Java String Whitespace Delete deleteWhitespace(final String str)

Here you can find the source of deleteWhitespace(final String str)

Description

delete Whitespace

License

Open Source License

Declaration

private static String deleteWhitespace(final String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static String deleteWhitespace(final String str) {
        if (str == null || str.isEmpty()) {
            return str;
        }/*from  w ww .jav a  2 s.  com*/
        final int sz = str.length();
        final char[] chs = new char[sz];
        int count = 0;
        for (int i = 0; i < sz; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                chs[count++] = str.charAt(i);
            }
        }
        if (count == sz) {
            return str;
        }
        return new String(chs, 0, count);
    }
}

Related

  1. deleteWhitespace(CharSequence sequence)
  2. deleteWhitespace(CharSequence str)
  3. deleteWhitespace(final String s)
  4. deleteWhitespace(String s)
  5. deleteWhiteSpace(String s)
  6. deleteWhitespace(String str)
  7. deleteWhitespace(String str)