Program to demonstrate StringTokenizer class in Java
Output of the program :
import java.util.StringTokenizer; public class StringTokenizerDemo { public static void main(String[] args) { System.out.println("Using , and = as delimiter ..... "); String input = "First Name=Dinesh," + "Last Name=Varyani," + "Blog Name=Learn Java by Examples," + "Blog Url=www.hubberspot.com"; StringTokenizer stringTokenizer = new StringTokenizer(input,"=,"); while(stringTokenizer.hasMoreElements()) { String info = stringTokenizer.nextToken(); String description = stringTokenizer.nextToken(); System.out.println(info + " : " + description); } System.out.println(); System.out.println("Using default delimiter which is whitespace ... "); input = "FirstName Dinesh " + "LastName Varyani " + "BlogName LearnJavaByExamples " + "BlogUrl www.hubberspot.com"; stringTokenizer = new StringTokenizer(input); while(stringTokenizer.hasMoreElements()) { String info = stringTokenizer.nextToken(); String description = stringTokenizer.nextToken(); System.out.println(info + " : " + description); } } }
Output of the program :