Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Iterator' - 11 question(s) found - Order By Newest | ||||
Frequently asked. | ||||
| ||||
Ans. Iterator is an interface that provides methods to iterate over any Collection. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   iterator Asked in 11 Companies basic   frequent | ||||
| ||||
Ans. http://www.buggybread.com/2015/01/java-iterator-classes-and-interfaces.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   iterator | ||||
| ||||
Ans. Fail-fast iterators detect illegal concurrent modification during iteration and fail quickly and cleanly rather than risking arbitrary, non deterministic behavior at an undetermined time in future. Example could be of an Iterator failing if it smells ConcurrentModificationException. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  fail-fast Iterators  Iterators Asked in 5 Companies intermediate | ||||
| ||||
Ans. No, iterator is an interface that is used to parse through the elements of a Collection | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections  iterator | ||||
| ||||
Ans. Though there are many differences the way internally they both iterates the collections and streams respectively, but the main difference in performance that is achieved by spliterator as it can iterate Streams in Parallel whereas iterator only iterates collections sequentially. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java8  java 8  spliterator  java 8 streams  streams | ||||
| ||||
Ans. Spliterator has better performance potential than iterators but only if the potential is used. Spliterator can iterate streams in parallel as well as in sequence whereas iterator can only iterate in sequence. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  iterator  collections  streams  parallel streams  Spliterator | ||||
| ||||
Ans. Enumeration Iterator List iterator | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  cursors  iterator | ||||
| ||||
Ans. Enumeration can iterate only legacy collections like Vector , HashTable and Stack whereas Iterator can iterate both legacy and non legacy collections. Enumeration is less safer than Iterator Enumeration is fail safe whereas Iterator is fail fast Iterator allows for removal of element while traversal whereas Enumeration doesn't have remove method. Enumerations were introduced in Java 1 whereas Iterators were introduced with Java 2 Enumerations have methods like hasMoreElements and nextElement whereas Iterators have methods like hasNext, next and remove | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  enumeration vs iterator  collections Basic   frequent | ||||
| ||||
Ans. This can be done using a Spliterator. LinkedList list = Arrays.asList("names","numbs","birds","animals"); Spliterator split1 = list.Spliterator(); Spliterator split2 = split1.Spliterator(); Now, the LinkedList is split into split1 and split2. use split2 first then split1 to check the output. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java 8  parallel stream  spliterator Asked in 1 Companies | ||||
| ||||
Ans. No,we cannot.I t will give concurrentModificationExceptin error. It can be resolved by using ConcurrentClasses like ConcurrentHashMap,CopyOnWriteArrayList,BlockingQueue etc which are fail-safe and wont give exception. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections  list  iterator Asked in 1 Companies basic | ||||
| ||||
Ans. CustomArrayList myarrayList = new CustomArrayList(); myarrayList.add("Value 1"); myarrayList.add("Value 2"); myarrayList.add("Value 3"); for (String string : myarrayList) { System.out.println(string); } package sample.utils; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class CustomArrayList implements Iterable { private ArrayList mylist = new ArrayList(); public void add(T t) { this.mylist.add(t); } @Override public Iterator iterator() { return new CustomIterator(mylist); } class CustomIterator implements Iterator { private int indexPosition = 0; private List internalList; public CustomIterator(List internalList) { this.internalList = internalList; } @Override public boolean hasNext() { if (internalList.size() >= indexPosition 1) { return true; } return false; } @Override public E next() { E val = internalList.get(indexPosition); indexPosition ; return val; } } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  iterator Asked in 1 Companies | ||||