Last updated 17. January 2021.
StringTokenizer in Java is a utility that allows you to break a string into pieces or multiple strings, called tokens.
For example, strings separated by a space and tabs are tokens. These markers are separated by a separator.
A delimiter is a group of characters that separates markers. Any character of the delimiter is considered a valid delimiter. For example, comma, semicolon and colon are restriction clauses.
By default, spaces, tabs, line breaks and carriage returns are used to separate lines. However, we can also use any other symbol to separate the markers.
Let’s take the example of the Java StringTokenizer.
Suppose we have the Hello Channel. If we define a space as a separator, this string will have the following three tokens:
- Hello
- Scientech
- Simply
If we put a comma as a separator after Hello, the next two tokens are on the same line:
- Hello
StringTokenizer was added in Java version 1.0 and is no longer part of the Java Collections Framework. It is included in the java.util package.
If you want to use StringTokenizer, you need to import the java.util package or at least the StringTokenizer class into your application.
StringTokenizer class declaration
The StringTokenizer class can be declared in the following general form:
the StringTokenizer
public class extends the
object and implements enumeration.
Related Tags:
stringtokenizer in java example, stringtokenizer vs split java, stringtokenizer trong java, stringtokenizer with multiple delimiters, stringtokenizer to array, stringtokenizer in java ppt, java tokenize string, stringtokenizer c++