Why does java.util.Iterator interface have remove() method?
Of course, sometimes this method is necessary, and they are all used to its presence. But in fact, the main and only goal of the iterator is simply to provide access container elements. And when someone wants to create their own implementation for this interface, and is unable or unwilling for some reason to provide the ability to delete an element, then he is forced to throw an UnsupportedOperationException . And throwing this exception usually indicates not too thought out architecture or some design flaws.
In fact, I do not understand the reasons for this decision. And I think it would be more appropriate to split a specific helper interface to support an optional method:

Any reasoned version, why remove() is part of Iterator ? Is this an example of a direct violation of SOLID sole responsibility SOLID ?
java iterator oop design-patterns solid-principles
kapand
source share