Pin It

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 : 

 
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot