• Post Reply Bookmark Topic Watch Topic
  • New Topic

fail fast and fail safe iterators

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List<address> list = new ArrayList<aaddress>();
Iterator it = list.iterator();
while(it.hasNext()){
Address ad = it.next();
System.out.println(ad.city);
}

In this code Iterator it is created. By default, is it fail safe or fail fast ? If its fail fat, how can I create fail safe iterator ?

----------------------------------------

List<address> list = new ArrayList<aaddress>();
Enumerator enum = list.elements();
while(enum.hasMoreElements()){
Address ad = enum.nextElement();
System.out.println(ad.city);
}

Is enumerator fail fast or fail safe ? If enumerator is fail safe, can I use fail fast enumerator or is it always fail safe only ?
 
Tony Docherty
Saloon Keeper
Posts: 3138
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nirjari patel wrote:List<address> list = new ArrayList<aaddress>();
Iterator it = list.iterator();
while(it.hasNext()){
Address ad = it.next();
System.out.println(ad.city);
}

In this code Iterator it is created. By default, is it fail safe or fail fast ? If its fail fat, how can I create fail safe iterator ?

----------------------------------------

List<address> list = new ArrayList<aaddress>();
Enumerator enum = list.elements();
while(enum.hasMoreElements()){
Address ad = enum.nextElement();
System.out.println(ad.city);
}

Is enumerator fail fast or fail safe ? If enumerator is fail safe, can I use fail fast enumerator or is it always fail safe only ?

Please remember to use code tags when posting code as it makes it far easier to read the code. You have posted here often enough now that you shouldn't really need reminding to do this.

For an explanation of these terms see: http://javarevisited.blogspot.co.uk/2012/02/fail-safe-vs-fail-fast-iterator-in-java.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!