answersLogoWhite

0

Define iterator in java

Updated: 12/23/2022
User Avatar

Wiki User

13y ago

Best Answer

An Iterator is a java feature using which we can loop through every single element of a collection and perform operations on them. It is extremely useful because we don't have to worry about the collection size or whether we will get index out of bounds exceptions while looping through a collection

Ex:

ArrayList lst = new ArrayList();

//code that populates the list

Iterator ir = lst.iterator();

Here itr is the iterator that will help the code loop through each element of the collection.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Define iterator in java
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the various functions in iterator class in java?

There are mainly three Methods available in the iterator class in java. Namely they are ... 1. Has Next 2. Next and 3. Remove.


Where is it possible to get a Java iterator?

The Oracle website has a step by step pattern that shows how to obtain an iterator for use with Java programming. HashMap can also be helpful with explaining the looping sequence.


What is difference Iterator and Enumeration?

1.Iterator has remove method while enumeration doesn't have it. 2.Iterator is new in Java API but Enumeration is older one. 3. Iterator extends functionality of Enumeration. 4. Iterator is more secure and safe as compared to Enumeration because it does not allow other thread to modify the collection object while some thread is iterating over it and throws ConcurrentModificationException.


Can you define variables in interface in java?

yes we can define a variable in an interface in java.


What is Re usability in java?

Reusability in Java means that once you write some code, you can use it over and over again - if you write it so that it can be reused. For example, if you write a Enumeration-Iterator adapter, or some code that lets you treat an Enumeration - Java legacy code - as an Iterator - shiny NEW Java code - then you can use it not only in your animal simulation program, but also in your Jacuzzi interface program.


What is vector in java?

victor is growvable object.. victor is legacy class it will support the iterator and enumarotor interfaces it is synchonyzied it will support like hasMoreElemetns and hasNext element


Define set in java?

A Java set is a collection of things that do not contain duplicate elements. Duplicates are prohibited from Java sets.


What is the hierarchy of the java program?

define the data types


What is function in java terminology?

In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.


How do you uss static in java?

It is uss to define class and method of pogrom's.


Name two high level languages and define them?

Java C++


Is java virtual machine dangerous?

JVM is a critical component in almost all Java platforms. I would hardly define it as "dangerous".