When debugging Java code using Eclipse, for collection variables, I saw the modcount member. What does it mean?
When debugging Java code using Eclipse, for collection variables, I saw the modcount member.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Many of Java’s collections produce iterators that are “fail-fast”, which means that if the collection is changed after an iterator is created, the iterator will be invalidated and throw a
ConcurrentModificationExceptionas soon as it can. (As compared to failing later or returning invalid data.)In order to support this functionality, the collection has to keep track of whether it has been modified. Each time the collection is changed, it increments
modcount. When the collection produces an iterator, the iterator stores the value ofmodcountfrom when it was created. Then whenever you try to use the iterator, it checks to see if its savedmodcountis different from the parent collection’s currentmodcount; if it is, the iterator fails with aConcurrentModificationException.(An exception to this rule is that modifications to the collection made through the iterator itself (like the iterator’s
removemethod) do not invalidate the iterator.)