So developing my server I store clients connections in a Set. While looping to send them data I use .iterator() to get Iterator and then call next() and send data through that channel I get with next(). Question, must I make new iterator from set every time? Can’t I just reset Iterator to start with first element again? If no, is there a slimer way of doing this since clients list don’t change much or at all. Maybe it’s normal, but I feel like it’s unnecesary to create iterator every time if I want to loop through it.
Thank you all.
Relax. its a small, short-lived object. Its not reallt costing you anything you are ever going to notice
And the answer is no. Iterators iterate ina foward direction only.