How use String tokenizer java

Write a function, tokenize_string(input_string, delimiter_list) that returns a list of strings that are separated by the delimiters.
For example: tokenize_string(“How now, Mrs. Brown Cow”) returns [‘How’, ‘now’, ‘Mrs’, ‘Brown’, ‘Cow’]

Solution: Please have sample java program which shows how to tokenize string java:

package com.javahonk.test;

import java.util.StringTokenizer;

public class TokenizeString {
	
	public static void main(String[] args) {

        String str = "How now, Mrs. Brown Cow";
        
        StringTokenizer stringTokenizer = new StringTokenizer(str, ",");
        
        while (stringTokenizer.hasMoreElements()) {
			System.out.println(stringTokenizer.nextElement());
			
		}
    }


}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *