Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is difference between Iterator and for loop

Answer Posted / deepesh

An "Iterator object" is used to move through a Collection,
by calling Collection's iterator() method. By using for
loop, you are limited to that particular collection you are
traversing, while iterator gives freedom to work with any
collection.

iterator's job is to move through the sequence (without the
client programmer knowing or caring about the underlying
structure & its modification) using hasNext() and next().
remove() is provided "to remove the last element returned by
the iterator" and is called only per call after next().

Iterator can be used for Lists and Sets for forward
(unidirectional) traversal of elements without knowing their
size, which is nearly same concept for for-each loop.

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a constructor call another constructor?

922


What is JVM and is it platform independent?

987


What flag up means?

978


What is your platform?s default character encoding and how to know this?

2318


If an application has multiple classes in it, is it okay to have a main method in more than one class?

965


What do you mean by global variable?

896


can used Protected Class outside Function.?

1049


Tell me the Importent classes in net package?

1946


What is function declaration?

908


What is user defined exception in Java?

1018


What are the pillars of java?

860


How do you read a char in java?

943


What are the differences between string, stringbuffer and stringbuilder?

961


Does java initialize arrays to zero?

959


When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?

1187