StringTokenizer method equivalence

后端 未结 2 568
栀梦
栀梦 2021-01-28 00:00

Why do hasMoreElements and hasMoreTokens return the same value?

相关标签:
2条回答
  • 2021-01-28 00:16

    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

    0 讨论(0)
  • 2021-01-28 00:36

    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.

    0 讨论(0)
提交回复
热议问题