Java - Write code to remove Spaces from a string with StringTokenizer

Requirements

Write code to remove Spaces from a string with StringTokenizer

Demo

//package com.book2s;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        System.out.println(removeSpaces(s));
    }//from  ww w. jav a 2s .c o  m

    public static String removeSpaces(String s) {
        StringTokenizer st = new StringTokenizer(s, " ", false);
        String t = "";
        while (st.hasMoreElements()) {
            t += st.nextElement();
        }
        return t;
    }
}