StringTokenizer in Java

Google Advertisements

String Handling in Java Data Conversion in Java

StringTokenizer in Java

It is a pre defined class in java.util package can be used to split the given string into tokens (parts) based on delimiters (any special symbols or spaces).

StringTokenizer injava

Suppose that we have any string like "Features of Java_Language" when we use stringTokenizer this string is split into tokens whenever spaces and special symbols present. After split string are :

Example

Features
of 
Java
Language

Methods of StringTokenizer

  • hasMoreTokens()
  • nextToken()

hasMoreTokens()

It is predefined method of StringTokenizer class used to check whether given StringTokenizer having any elements or not.

nextToken()

Which can be used to get the element from the StringTokenizer.

Example of StringTokenizer:

Example of StringTokenizer

import java.util.*;
class Stringtokenizerdemo
{
public static void main(String args[])
{
String str="He is a gentle man";
StringTokenizer st=new StringTokenizer(str," ");
System.out.println("The tokens are: ");
while(st.hasMoreTokens())
{
String one=st.nextToken();
System.out.println(one);
}
}
}

Output

The tokens are:
He
is
a
gentle
man

String Handling in Java Data Conversion in Java

Google Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs