- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The iterator() method of Java AbstractCollection class
The iterator() method of the AbstractCollection class in Java is used to return an iterator over the elements contained in this collection.
The syntax is as follows −
public abstract Iterator<E> iterator()
To work with AbstractCollection class in Java, import the following package −
import java.util.AbstractCollection;
For Iterator, import the following package −
import java.util.Iterator;
The following is an example to implement the AbstractCollection iterator() method in Java −
Example
import java.util.Iterator; import java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) { AbstractCollection<Object> absCollection = new ArrayList<Object>(); absCollection.add("Laptop"); absCollection.add("Tablet"); absCollection.add("Mobile"); absCollection.add("E-Book Reader"); absCollection.add("SSD"); absCollection.add("HDD"); System.out.println("AbstractCollection = " + absCollection); System.out.println("Iterating elements one by one..."); Iterator i = absCollection.iterator(); while (i.hasNext()) { System.out.println(i.next()); } } }
Output
AbstractCollection = [Laptop, Tablet, Mobile, E-Book Reader, SSD, HDD] Iterating elements one by one... Laptop Tablet Mobile E-Book Reader SSD HDD
- Related Articles
- The containsAll() method of Java AbstractCollection class
- The isEmpty() method of Java AbstractCollection class
- The toArray() method of Java AbstractCollection class
- The toString() method of Java AbstractCollection class
- The remove() method of Java AbstractCollection class
- The size() method of Java AbstractCollection class
- The addAll() method of Java AbstractCollection class
- The clear() method of Java AbstractCollection class
- The contains() method of Java AbstractCollection class
- The iterator() method of Java AbstractSequentialList class
- The iterator() method of AbstractList class in Java
- The toArray(T[] a) T method of Java AbstractCollection class
- What is AbstractCollection class in Java?
- The iterator() method of CopyOnWriteArrayList in Java
- DoubleStream iterator() method in Java

Advertisements