Android String Remove removeWhitespace(String str)

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

Description

remove Whitespace

Declaration

public static String removeWhitespace(String str) 

Method Source Code

//package com.java2s;

public class Main {

    public static String removeWhitespace(String str) {
        if (isEmpty(str)) {
            return str;
        }//from  ww w  .j  a va 2 s. com
        int sz = str.length();
        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);
    }

    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }
}

Related

  1. removeAccents(String string)
  2. removeBackslashes(String content)
  3. removeDuplicates(String[] first, String[] second)
  4. removeSpace(String str)
  5. removeSuffix(String str, String suffix)
  6. rmvSpace(String baseStr)
  7. rmvSpecial(String baseStr)
  8. removeBlanks(String content)
  9. rmvBlankLines(String input)