Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

StringTokenizer class in Java

Program to demonstrate StringTokenizer class in Java

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 : 

 
 
© 2021 Learn Java by Examples Template by Hubberspot