What is the difference between (Enumeration, Iterator, Loop) ??
In the following code each example (Enumeration, Iterator, Loop) gets the same output ] but I need to know what is the real difference between them? Is there specific case where i should use one of them and cant use the others? any advantages in one of them over the others?
Enumeration VS Iterator
Iterator is mainly used with non Thread safe Collection. Iterator is designed in such a way that it fails whenever concurrent modification are made to the Collections i.e if a collection which is made for single Threaded environment is used in multithreaded environment and changes are made to it by Thread while it is being traversed then the traversing fails.
Enumeration is used only with Thread safe Collection. When such a collection is used in multithreaded environment consistency of the data is guarantee hence Enumeration never fails
For better understanding you should their Internal Working........
A Collection and its Iterator and Enumeration has a stronger HAS-A relation between them i.e Existence of both parties depends upon each other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With