问题
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
回答1:
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.
回答2:
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
回答3:
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.
回答4:
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.
回答5:
hasMoreElements returns the same value as the hasMoreTokens method. It exists so that this class can implement the Enumeration interface.
来源:https://stackoverflow.com/questions/17080351/what-is-difference-between-hasmoreelements-and-hasmoretokens-in-stringtokenizer