iterating through Enumeration of hastable keys throws NoSuchElementException error

后端 未结 7 919
没有蜡笔的小新
没有蜡笔的小新 2021-02-11 11:50

I am trying to iterate through a list of keys from a hash table using enumeration however I keep getting a NoSuchElementException at the last key in list?

Hasht         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-11 12:33

    You're calling nextElement twice in the loop. You should call it only once, else it moves ahead twice:

    while(e.hasMoreElements()){
        String s = e.nextElement();
        System.out.println(s);
    }
    

提交回复
热议问题