0% found this document useful (0 votes)
3 views8 pages

Venkatesh Maipathii

Uploaded by

MONICA NAHAK
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)
3 views8 pages

Venkatesh Maipathii

Uploaded by

MONICA NAHAK
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
You are on page 1/ 8

Dt : 26/9/2023

Diagram:

ii
ath
aip
hM
a tes
nk

==============================================================
Ve

hasMoreTokens() : hasMoreTokens() method will move the cursor on

StringTokenizer Object and check the token available or

not.

If Token available returns "true",else resturns "false".


nextToken() : nextToken() will retrieve and delete token from the Object

nextToken(String) : nextToken(String) will take delimiter as parameter and

break the retrieved token into pieces.

ii
hasMoreElements() : hasMoreElements() method will move the cursor on

ath
StringTokenizer Object and check the token available or

not.

aip
If Token available returns "true",else resturns "false".
hM
nextElement() : nextElement() will retrieve and delete token from the

Object
tes

countTokens() : countTokens() will display the count of tokens.

===================================================================
a
nk

Program : DemoTokenizer2.java
Ve

package maccess;
import java.util.*;
public class DemoTokenizer2 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
try(s;){
System.out.println("Enter the String:");
String str = s.nextLine();
System.out.println("Enter the delimiter:");
String dl = s.nextLine();
StringTokenizer ob = new
StringTokenizer(str,dl);
System.out.println("str : "+str.toString());
System.out.println("Count of
Tokens:"+ob.countTokens());
System.out.println("*****Tokens*****");
while(ob.hasMoreTokens())
{
String ele = ob.nextToken("a");

ii
System.out.println("Token : "+ele+" ");

ath
}//end of loop
System.out.println("Count of
Tokens:"+ob.countTokens());
}//end of try with resource

aip
}
}
hM
o/p:

Enter the String:


tes

java language program

Enter the delimiter:


a
nk

str : java language program


Ve

Count of Tokens:3

*****Tokens*****

Token : j

Token : v

Token : l
Token : ngu

Token : ge progr

Token : m

Count of Tokens:0

========================================================

ii
Ex-program:

ath
wap to read a string and display the reverse of words from the given

String?

i/p : java langauge program

aip
hM
o/p : avaj eguagnal margorp

Program : DemoTokenizer3.java
tes

package maccess;
import java.util.*;
public class DemoTokenizer3 {
a

public static void main(String[] args) {


nk

Scanner s = new Scanner(System.in);


try(s;){
System.out.println("Enter the String:");
Ve

String str = s.nextLine();


System.out.println("Enter the delimiter:");
String dl = s.nextLine();
StringTokenizer ob = new StringTokenizer(str,dl);
System.out.println("str : "+str.toString());
System.out.println("****After reverse****");
while(ob.hasMoreTokens())
{
String ele = ob.nextToken();
StringBuffer sb = new StringBuffer(ele);
System.out.print(sb.reverse()+" ");
}//end of loop
}//end of try with resource
}
}

o/p:

ii
ath
Enter the String:

java is simple,secure.Java is Robust.

Enter the delimiter:

,.

aip
hM
str : java is simple,secure.Java is Robust.

****After reverse****

avaj si elpmis eruces avaJ si tsuboR


tes

=================================================================

Assignment-1:
a

wap to read a String and display reverse of words which starts with Vowel?
nk
Ve

i/p : Java Book is on the Table and cat is under the table.

o/p : Java Book si no the Table dna cat si rednu the table

Assignment-2 :

wap to read a String and display reverse of Words which ends with
Consonent?

i/p : Java is simple,secure,Robust.Java is multithreaded.

o/p : java si simple secure tsuboR Java si dedserhtitlum

===================================================================

ii
(b)StringJoiner class(Java8 - new Component)

ath
=>StringJoiner class is from java.util package introduced by Java8

version and which is used to join the strings based on delimiter.

aip
=>The following are some important methods from StringJoiner:
hM
public java.util.StringJoiner(java.lang.CharSequence);

public java.util.StringJoiner setEmptyValue(java.lang.CharSequence);


tes

public java.lang.String toString();

public java.util.StringJoiner add(java.lang.CharSequence);


a
nk

public java.util.StringJoiner merge(java.util.StringJoiner);

public int length();


Ve

Program : DemoJoiner.java
package maccess;
import java.util.*;
public class DemoJoiner {
public static void main(String[] args) {
StringJoiner ob1 = new StringJoiner("/");
ob1.setEmptyValue("data not available....");
System.out.println(ob1.toString());
System.out.println("****Add date of
Joining****");
ob1.add("12");
ob1.add("09");
ob1.add("2023");
System.out.println("DOJ : "+ob1.toString());
System.out.println("****Add address****");
StringJoiner ob2 = new StringJoiner("-");

ii
ob2.add("HYD");

ath
ob2.add("TS");
ob2.add("605112");
System.out.println("Address : "+ob2.toString());
System.out.println("*****After merge()*****");

aip
ob1.merge(ob2);
System.out.println(ob1.toString());
System.out.println("length of ob1 :
"+ob1.length());
hM
}
}
tes

o/p:
a

data not available....


nk

****Add date of Joining****


Ve

DOJ : 12/09/2023

****Add address****

Address : HYD-TS-605112

*****After merge()*****

12/09/2023/HYD-TS-605112
length of ob1 : 24

=================================================================

faq:

define setEmptyValue() method?

=>setEmptyValue() method will add msg to StringJoiner object and which

ii
is displayed when we display empty StringJoiner object.

ath
faq:

aip
wt is the diff b/w

(i)append()
hM
(ii)add()

=>append() method is used to add data to StringBuffer and StringBuilder


tes

Objects.

=>add() method is used to add data to StringJoiner Object.


a
nk

==============================================================
Ve

You might also like