public String reverseWords(String s) {
        if (s == null || s.length() == 0) {
            return s;
        }
        
        s = s.trim();
        Queue<String> queue = new LinkedList<String>();
        int i = 0;
        int start = 0;
        while (i < s.length()) {
            while (i < s.length() && s.charAt(i) != ' ') {
                i++;
            }
            queue.offer(s.substring(start, i));
            while (i < s.length() && s.charAt(i) == ' ') {
                i++;
            }
        }
        
        /* generate reversed string */
        StringBuilder strbuilder = new StringBuilder();
        while (!queue.isEmpty()) {
            strbuilder.append(queue.poll());
            strbuilder.append(' ');
        }
        strbuilder.setLength(strbuilder.length() - 1);
        return strbuilder.toString();
    }