Why do hasMoreElements
and hasMoreTokens
return the same value?
From the javadoc of hasMoreElements()
/**
* Returns the same value as the hasMoreTokens
* method. It exists so that this class can implement the
* Enumeration interface.
*/
Javadoc
since this is a legacy class which implements Enumeration it also uses the method hasMoreTokens for simplicity method naming.
In simple case which uses just the StringTokenizer you can use the hasMoreTokens method. In polymorphic case which you created or already has more implementation of the Enumeraion interface you will use the hasMoreElements which is part of the Enumeraion interface.