I came across this bit of code to remove strings of even length from given Linked list
I don't understand why the iterator object itr
not instantiated with new
keyword. here is the code..
public static void removeEvenLength(List<String> list) {
Iterator<String> itr= list.iterator();
while (itr.hasNext()) {
String element=itr.next();
if (element.length()%2==0) {
i.remove();
}
}
}
Does it mean here, that the iterator method is static
and it just returns a new iterable object
with list
as its field
. can someone provide with me one or more examples where similar way of instantiating is encountered in Java other than singleton constructors I suppose.
Thank you