3

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

Craig
  • 1,390
  • 7
  • 12
dev09
  • 159
  • 3
  • 11
  • Looks like that method exists just to conform to the [Enumeration interface](http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Enumeration.html). – Supericy Jun 13 '13 at 06:15

5 Answers5

6

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.

Community
  • 1
  • 1
Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
1

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

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
1

There seems be no difference as the javadoc says:

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

boolean hasMoreTokens() Tests if there are more tokens available from this tokenizer's string.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
0

From the Javadocs:

boolean hasMoreElements()
Returns the same value as the hasMoreTokens method.

boolean hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string.
Kai
  • 38,985
  • 14
  • 88
  • 103
0

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

tbsalling
  • 4,477
  • 4
  • 30
  • 51