What is difference between Iterator and for loop
Answer Posted / a.jyotsna
The Iterator is not implemented as an
indexed loop, at least not in Sun Java. The collection
always has a
getter armed with the iterator's next value. Much of the
collection's
internal implementation is done via the iterator. But the
pieces of
ArrayList that are optimized for speed, skip bounds
checking and use int
array offsets to do their work.
I would like to know what is the difference between these 2.
>
> ArrayList list = new ArrayList
>
> for(int i=0; i<list.size(); i++){
> //do stuff
> }
>
> Iterator i = list.iterator();
>
> while(i.hasNext(){
> do stuff
> }
Is This Answer Correct ? | 6 Yes | 6 No |
Post New Answer View All Answers
Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?
hr interview how many minutes asking question
Which collection is thread safe in java?
What is indexof?
What is a boolean field?
What are the differences between string and stringbuffer?
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Define how can we find the actual size of an object on the heap?
What is composition in java?
Can a hashset contain duplicates java?
What is classes in java?
How many types of keywords are there?
can rmi and corba based applications interact ?
What is array length?
What is charat ()?