0% found this document useful (0 votes)
2 views2 pages

StringTokenizer Constructors

The document presents three Java constructors using the StringTokenizer class to tokenize a string. Constructor 1 splits the string by whitespace, resulting in 5 tokens, while Constructor 2 splits by commas, yielding 2 tokens. Constructor 3 includes the delimiters in the output, resulting in 3 tokens, demonstrating different ways to tokenize a string in Java.

Uploaded by

Aravind Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

StringTokenizer Constructors

The document presents three Java constructors using the StringTokenizer class to tokenize a string. Constructor 1 splits the string by whitespace, resulting in 5 tokens, while Constructor 2 splits by commas, yielding 2 tokens. Constructor 3 includes the delimiters in the output, resulting in 3 tokens, demonstrating different ways to tokenize a string in Java.

Uploaded by

Aravind Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CONSTRUCTOR 1:

import [Link];
class constructors
{
public static void main(String args[])
{
String str="java is a programming ,language";
StringTokenizer st=new StringTokenizer(str);
[Link]([Link]());
while([Link]())
{
[Link]([Link]());
}
}
}

OUTPUT:
5
java
is
a
programming
,language

CONSTRUCTOR 2:

import [Link];
class constructors
{
public static void main(String args[])
{
String str="java is a programming ,language";
StringTokenizer st=new StringTokenizer(str,”,”);
[Link]([Link]());
while([Link]())
{
[Link]([Link]());
}
}
}

OUTPUT:
2
java is a programming
language

CONSTRUCTORS 3:

import [Link];
class constructors
{
public static void main(String args[])
{
String str="java is a programming ,language";
StringTokenizer st=new StringTokenizer(str,”,”,true);
[Link]([Link]());
while([Link]())
{
[Link]([Link]());
}
}
}

OUTPUT:
3
java is a programming
,
language

You might also like