private static String clearSpaceWithChar(String s) {
    s = s.trim();
    int count = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s.charAt(i) == ' ') {
        if (s.charAt(i - 1) == ' ') {
          count++;
        }
      }
    }
    int charLen = s.length() - count;
    char[] temp = new char[charLen];
    int j = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s.charAt(i) != ' ') {
        temp[j++] = s.charAt(i);
      } else {
        if (s.charAt(i - 1) != ' ') {
          temp[j++] = s.charAt(i);
        }
      }
    }
    return new String(temp);
  }