1. Iterator Declaration



Yüklə 56 Kb.
səhifə3/3
tarix22.07.2023
ölçüsü56 Kb.
#137103
1   2   3
Iterator Vs. Collection

  • Iterator can only move to next() element or remove() an element. 
    However Collection can add(), iterate, remove() or clear() the elements of the collection. 

  • Iterator provides a better speed than Collections, as the Iterator interface has limited number of operations. 

  • java.sql.SQLException extends Iterable. Hence it allows the caller to safely iterate over causes of SQLException. 
    Using a collection, in this case, would be expensive because, in a chain of n exceptions, use of a collection in the SQLException interface would potentially require the construction of O(n^2) elements. 
    However, use of Iterable provides O(n) access to the exception chain. 


Last Updated : 01 Mar, 2023
3
Similar Reads
1.Retrieving Elements from Collection in Java (For-each, Iterator, ListIterator & EnumerationIterator)
2.How to Remove an Element from Collection using Iterator Object in Java?
3.Java Program to Get the Size of Collection and Verify that Collection is Empty
4.Java Program to Add the Data from the Specified Collection in the Current Collection
5.Difference Between Collection.stream().forEach() and Collection.forEach() in Java
6.Iterator vs Foreach In Java
7.How to use Iterator in Java?
8.TreeSet iterator() Method in Java
9.LinkedBlockingDeque iterator() method in Java
10.IntStream iterator() in J
Yüklə 56 Kb.

Dostları ilə paylaş:
1   2   3




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin