I'm from a C# background where the iterators implement IDisposable interface. Are there any iterators in Java that implement a similar interface that makes them close automatically?
Java's Iterator is just an abstraction for iterating over some collection of objects. If the underlying data structure needs some clean-up after iteration (e.g. closing a file), then you need to keep a reference to that underlying object so you can do whatever must be done to "dispose" of it.
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