public String reverseWords2(String s) {

    if (s == null) {
      return null;
    }

    s = s.trim();
    int start = 0;
    int runner = 1;
    boolean spaceFlag = false;
    Stack<String> stack = new Stack<String>();
    while (runner <= s.length()) {
      if (!spaceFlag && ' ' == (s.charAt(runner - 1))) {
        stack.push(s.substring(start, runner));
        start = runner;
        spaceFlag = true;
      } else if (spaceFlag && !(' ' == s.charAt(runner - 1))) {
        stack.push(s.substring(start, runner));
        start = runner;
        spaceFlag = false;
      } else if (runner == s.length()) {
        stack.push(s.substring(start, runner));
      }
      runner++;
    }

    StringBuilder sb = new StringBuilder();
    while (!stack.isEmpty()) {
      sb.append(stack.pop());
    }

    return sb.toString();
  }