ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
What is difference between Iterator and for loop
 Question Submitted By :: Vikash
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is difference between Iterator and for loop
Answer
# 1
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 ?    3 Yes 1 No
A.jyotsna
 
  Re: What is difference between Iterator and for loop
Answer
# 2
Iterator is used in Collection objects,but for is used for 
variables.
 
Is This Answer Correct ?    1 Yes 3 No
Srikanth Nallapaneni
 
 
 
  Re: What is difference between Iterator and for loop
Answer
# 3
In iterator the remove() is available to remove the
content/item but in for loop  remove() not available.
 
Is This Answer Correct ?    3 Yes 2 No
Vijayakumar Chinnasamy
 
  Re: What is difference between Iterator and for loop
Answer
# 4
The major difference is Iterator doesn't output the list we 
are iterating in sequence.
where as in for we structure it to print in sequence.
 
Is This Answer Correct ?    2 Yes 2 No
Sundarakannan D
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
diff between abstract methods and interfaces with programing (code) example?  2
why java does not support mulitple inheritance directly? TCS2
Why Wait and notify are kept in Object class although they are used only with Thread Class Saksoft2
What is emant by API? is it related to java only or it is common for all OOPS supporting language?  2
Hi Friends, I am beginner in java. what i know about synchonized keyword is,If more that one 1 thread tries to access a particular resource we can lock the method using synchronized keyword. Then after that how the lock is released and how next thread access that.Please explain with example.  1
byte a=5; byte b=5; byte c=a+b; System.out.println(c); whats the o/p? Wipro5
what is the use of abstract class? AMDOC2
what is Thread?  6
How to do validation of the fields in any project ?  2
Iterator in the HashMap is fail-safe means what? IBM9
whats the life cycle of jsp Satyam11
What is operator?  2
What is an Iterator interface?  2
What is Locale class? MySoft1
how can u create the object with out new operator  2
how can we use the servlet as standalone apllication?should we need to extend any class? Logica-CMG2
What is hard code & soft code? Wipro4
what is diff bet iterator and enumeration?  2
Can u write constructor in abstract.If yes den when it will be invoked. SunGard3
Why we use static and synchronized in method for single thread model example: public static synchronized add(){}  1
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com