Code example for StringTokenizer

Methods: hasMoreTokens, nextToken

0
    public void setGreeting(Greeting greetingSvc) {
        this.greetingSvc = greetingSvc;
    } 
 
    public void execute(String line, PrintStream out, PrintStream err) {
        StringTokenizer tokenizer = new StringTokenizer(line);
        tokenizer.nextToken(); // discard first token
 
        String name = "";
        if (tokenizer.hasMoreTokens())
            name = tokenizer.nextToken();
 
        System.out.println(greetingSvc.sayHello(name));
    } 
     
    public String getName() {
        return "greet"; 
    } 
     
    public String getShortDescription() {
        return "Example command";