StringTokenizer class in Java is used to break a string into tokens.
A StringTokenizer object internally maintains a current position within the string to be tokenized. Some operations advance this current position past the characters processed.
A token is returned by taking a substring of the string that was used to create the StringTokenizer object.
StringTokenizer(String str) : str is string to be tokenized. Considers default delimiters like new line, space, tab, carriage return and form feed. StringTokenizer(String str, String delim) : delim is set of delimiters that are used to tokenize the given string. StringTokenizer(String str, String delim, boolean flag): The first two parameters have same meaning. The flag serves following purpose. If the flag is false, delimiter characters serve to separate tokens. For example, if string is "hello geeks" and delimiter is " ", then tokens are "hello" and "geeks". If the flag is true, delimiter characters are considered to be tokens. For example, if string is "hello geeks" and delimiter is " ", then tokens are "hello", " " and "geeks".
Using Constructor 1 - Hello Geeks How are you Using Constructor 2 - JAVA Code String Using Constructor 3 - JAVA : Code : String
We will soon be discussing methods of StringTokenizer in separate posts.
This article is contributed by Mohit Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- StringTokenizer methods in Java with Examples | Set 2
- C++ Internals | Default Constructors | Set 1
- Inheritance and constructors in Java
- Constructors in Java
- Constructors in C++
- Byte Class Fields in Java with example
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.util.BitSet class in Java with Examples | Set 1
- Java.io.DataInputStream class in Java | Set 2
- Java.lang.String class in Java | Set 2
- java.lang.Character class methods | Set 1
- BitSet class methods in Java with Examples | Set 3
- Math class methods in Java with Examples | Set 2
- java.math class and its methods | Set 1
- java.lang.Character class - methods | Set 2
- String class in Java | Set 1
- Output of Java Programs | Set 52 (Strings Class)
- Java.io.File Class in Java
- Java.util.zip.GZIPInputStream class in Java
- Java.io.LineNumberReader class in Java