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

独自空忆成欢 提交于 2019-12-01 09:38:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!