• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fast fail behavior of collection

 
Vab Gandhi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to know more about fast fail behavior of collection objects.I know due to this ,if i try to chage my collection object while iterating on it throws ConcurrentModificationException.But if it is not allowed then how is it possible to update the underlying collection object (i mean reduce its size) using iterator objects' remove() method which removes the last object returned on next() method call? Also if i use Vector object it is possible to iterate and update collection object without any exception. Why this difference between Vector class object and object of other collection classes? Also i want know when to use Vector and when to use ArrayList ?

Thanking in advance.....
Vab
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Follow this tutorial:

http://java.sun.com/docs/books/tutorial/collections/index.html

Best of luck.
 
Vab Gandhi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for reply,
But sorry , i wanted precise description for Fast Fail behavior of Collection object. U suggested me tutorial about Collection API.So please give me any tutorial link if u know relating to fast fail behavior.
Thanx in advance
Vab
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vab,

The Tutorial explains about Fast fail behavior indeed. Though the explanation is brief.

General Purpose Implementation

The problem is when you are iterating through a list using iterator interface in a thread, and another(or same) thread changes the underlying list, the iterator operation fails immediately.
In case of Vector (or Hashtable), the Enumeration interface behaves inderterministic way under the same situation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic