Code example for StringTokenizer

Methods: hasMoreTokensnextToken

0
        checkValue("a", st1.nextToken("b"));
        st1.hasMoreTokens();
        checkValue("b", st1.nextToken(""));
 
        // Test with retDelims set to true 
        StringTokenizer st2 = new StringTokenizer("abcd efg", "abc", true);
        st2.hasMoreTokens();
        checkValue("a", st2.nextToken("bc"));
        st2.hasMoreTokens();
        checkValue("b", st2.nextToken());
        st2.hasMoreTokens();
        checkValue("cd", st2.nextToken(" ef"));
        st2.hasMoreTokens();
        checkValue(" ", st2.nextToken(" "));
        st2.hasMoreTokens();
        checkValue("ef", st2.nextToken("g"));
        st2.hasMoreTokens();
        checkValue("g", st2.nextToken("g"));
 
        // Test with changing delimiters 
        StringTokenizer st3 = new StringTokenizer("this is,a interesting,sentence of small, words", ",");
        st3.hasMoreTokens();
        checkValue("this is", st3.nextToken()); // "this is"