The StringTokenizer class provides a method to break a string into token parsing, a string involves breaking the string into different words. These words are called Tokens. The StringTokenizer uses white spaces(default) as separators. This is known as delimiters.

To use StringTokenizer, you specify an input string and a string that contains delimiters. Delimiters are characters that separate tokens. Each character in the delimiters string is considered a valid delimiter-for example, “;”   sets the delimiters to a semicolon. The nextToken()  method returns the next token in the string.


Program Source

import java.util.StringTokenizer;

public class Javaapp {

    public static void main(String[] args) {
        String studentdata = "student1 : 40;student2 : 50;student3 : 60;";
        StringTokenizer st = new StringTokenizer(studentdata,";");
        String s1 = st.nextToken();
        String s2 = st.nextToken();
        String s3 = st.nextToken();

Leave a Comment