Java - Write code to replace All Empty space in a string

Requirements

Write code to replace All Empty space in a string

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String raw = "b oo  k2s.com";
        System.out.println(replaceAllEmpty(raw));
    }//  w  w  w.  j a v  a  2 s  . c  o m

    public static String replaceAllEmpty(String raw) {
        if (isEmpty(raw)) {
            return raw;
        }
        raw = raw.trim();
        String[] empties = new String[] { " ", "\r", "\n" };
        for (String string : empties) {
            raw = raw.replaceAll(string, "");
        }
        return raw;
    }

    public static boolean isEmpty(String raw) {
        if (null == raw || raw.trim().length() == 0
                || "null".equals(raw.trim())) {
            return true;
        }
        return false;
    }
}

Related Exercise