StringTokenizer method equivalence

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

Why do hasMoreElements and hasMoreTokens return the same value?

2条回答
  •  耶瑟儿~
    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.

提交回复
热议问题