Source Code:
(back to article)
Submit
Result:
Report an issue
import java.util.StringTokenizer; public class StringTokenizerExample { public static void main(String[] args) { StringTokenizer st = new StringTokenizer("A StringTokenizer sample"); // get how many tokens are inside st object System.out.println("Tokens count: " + st.countTokens()); // iterate st object to get more tokens from it while (st.hasMoreElements()) { String token = st.nextElement().toString(); System.out.println("Token = " + token); } } }