Java String Whitespace Delete deleteWhitespace(String s)

Here you can find the source of deleteWhitespace(String s)

Description

delete Whitespace

License

Open Source License

Parameter

Parameter Description
s a parameter

Return

a copy of the given string without any white space character.

Declaration

public static String deleteWhitespace(String s) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

public class Main {
    /**/* w  ww. jav  a2  s .co m*/
     * @param s
     * @return a copy of the given string without any white space character.
     * @postcondition (s == null) --> result == null
     */
    public static String deleteWhitespace(String s) {
        final String result;
        if (s == null) {
            result = null;
        } else {
            final StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                final char c = s.charAt(i);
                if (!Character.isWhitespace(c)) {
                    sb.append(c);
                }
            }
            result = sb.toString();
        }
        assert (s != null) || result == null;
        return result;
    }
}

Related

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