Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between hasmoreelements and hasmoretokens in stringtokenizer java? [duplicate]

I am very much confused between hasmoreelements and hasmoretokens method of stringtokenizer.

I want to know what's the difference

Can anybody clear my confusion?

Thanks

like image 796
dev09 Avatar asked Sep 07 '25 05:09

dev09


2 Answers

I want to know what's the difference

From the Java API doc:

hasMoreElements()

Returns the same value as the hasMoreTokens method. It exists so that this class can implement the Enumeration interface.

There is no difference from a functional perspective.

hasMoreElements() needs to be there because StringTokenizer implements the Enumeration interface.

like image 152
Andreas Fester Avatar answered Sep 09 '25 01:09

Andreas Fester


As per API

public boolean hasMoreTokens()

Returns true if more tokens exist.

public boolean hasMoreElements()

Returns true if the Enumeration has more elements.

So Bottem line is they are same and It supports Enumeration

like image 41
Suresh Atta Avatar answered Sep 09 '25 03:09

Suresh Atta