StringTokenizer in java example

 

String Tokenizer in java example

In java, String Tokenizer is used to split a string into the tokens which is defined by delimiter. We are giving example of String tokenizer how to use in java. StringTokenizer class is found in java.util.StringTokenizer package.

	package com.string.tokenizer;

	import java.util.StringTokenizer;

	public class StringTokenizerUsingDelimiterExample {

		/**
		 * Java StringTokenizer Using Delimiter example.
		 * This example help you to use String Tokenizer object with Delimiter
		 */
		public static void main(String[] args) {
			
			String tokenString = "String Tokenizer with delimiter";
			
			String delimiter = " ";
			
			StringTokenizer stringtoken = new StringTokenizer(tokenString, delimiter);
			
			// hasMoreTokens method of string tokenizer 
			//returns booleans value to iterate
			while(stringtoken.hasMoreTokens()){
			    //Returns the next token from this string tokenizer in String.  
				System.out.println(stringtoken.nextToken());
			}
		}

	}


Output String Tokenizer


String
Tokenizer
with
delimiter

Tags:

 

Leave a Reply