StringTokenizer in Java

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
เว็บคล้าย ib888
String Handling in Java Data Conversion in Java

Google Advertisment

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

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

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements