Iterate an Enumeration in Java 8

(This answer shows one of many options. Just because is has had acceptance mark, doesn’t mean it is the best one. I suggest reading other answers and picking one depending on situation you are in. IMO:

  • for Java 8 Holger’s answer is nicest, because aside from being simple it doesn’t require additional iteration which happens in my solution.
  • for Java 9 I would pick solution describe in Tagir Valeev answer)

You can copy elements from your Enumeration to ArrayList with Collections.list and then use it like

Collections.list(yourEnumeration).forEach(yourAction);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)