Home » Core Java » util » StringTokenizer » Tokenize String with StringTokenizer

About Ilias Tsagklis

Avatar photo
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Tokenize String with StringTokenizer

In this example we shall show you how to tokenize a String with StringTokenizer. The StringTokenizer is used to break a String into tokens. To tokenize a String with StringTokenizer one should perform the following steps:

  • Get a new StringTokenizer for a specified String, using the StringTokenizer(String str) constructor.
  • Get the tokens of the String, using hasMoreTokens() and nextToken() API methods of StringTokenizer. Since no delimiter has been set, one of the delimiters in the default delimiter set is used, that is here the space character,

as described in the code snippet below.

package com.javacodegeeks.snippets.core;

import java.util.StringTokenizer;

public class TokenizeStringWithStringTokenizer {
	public static void main(String[] args) {
		StringTokenizer st = new StringTokenizer("Java Code Geeks - Java Examples");
		// lop through tokens
		while(st.hasMoreTokens()) {




This was an example of how to tokenize a String with StringTokenizer in Java.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....


Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions


Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments