This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

fail fast and fail safe iterators  RSS feed

 
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
Bartender
Posts: 3268
82
  • 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!