iterating through Enumeration of hastable keys throws NoSuchElementException error

后端 未结 7 2374
梦谈多话
梦谈多话 2021-02-11 11:51

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:45

    Every time you call e.nextElement() you take the next object from the iterator. You have to check e.hasMoreElement() between each call.


    Example:

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

提交回复
热议问题