MEWAR INTERNATIONAL UNIVERSITY,
MASAKA
FACULTY OF COMPUTING AND SCIENCES
DEPARTMENT OF COMPUTER SCIENCE
COURSE CODE:
COS 202
COURSE TITLE:
COMPUTER PROGRAMMING II
TOPIC:
AN IN-DEPTH ANALYSIS OF JAVA COLLECTIONS:
ITERATOR AND ENUMERATION INTERFACES
ASSIGNMENT
DATE;
FEBRUARY, 2026
GROUP 0NE
S/N NAME MATRIC NO
1 HASSAN MUHAMMAD ILLE MIUSTD2024003
2 DOKI ROBERT TERKUMA MIUSTD2024014
3 NUHU MUHAMMAD MIUSTD2024019
4 YAQUB HASSANA ALHASSAN MIUSTD2024054
5 KHALID ABDULLAHI UMAR MIUSTD2024064
6 BARAU SUEDER LILY MIUSTD2024084
7 AISHA MOHAMMED SANI MIUSTD2024086
8 ABUBAKAR DAHIRU MIUSTD2024087
9 MAHMOUD SANI AHMED MIUSTD2024089
10 FATIMA BAKARI ADAMU MIUSTD2024095
11 SA'ADATU AWWAL MOHAMMED MIUSTD2024117
12 USMAN ISMAIL MIUSTD2024124
13 ABDULMAJID RABO SHUAIBU MIUSTD2024129
14 GODWIN DAVID OCHAI MIUSTD2024136
15 DEBORAH OLUWAFERAMMI BOLARIN MIUSTD2024139
16 MUHAMMED MUBARAK MUSA MUHAMMED MIUSTD2024142
17 VICTOR OGHENERUESE IDJERHEFERE MIUSTD2024144
18 BUKAR WOBI ALI MIUSTD2024145
19 MUJAHID KABIRU MIUSTD2024154
20 MISA ABDULMALIK ADAMU MIUSTD2024155
21 ABULRAHMAN MUHAMMAD SANI MIUSTD2024159
22 MUHAMMAD MUAZU IDRIS MIUSTD2024172
23 ZUBAIDA RUAFAI MIUSTD2024182
24 AMINA TIJJANI GAYA MIUSTD2024195
25 ABDULLAHI WOBI ALI MIUSTD2024196
26 ABDULRAHMAN IBRAHIM ABUBAKAR MIUSTD2024198
27 NAZIFI ALIYU BALARABE MIUSTD02025459
ABSTRACT
This technical report provides a comprehensive analysis of traversal mechanisms within the Java
Collections Framework (JCF), specifically focusing on the Iterator and Enumeration interfaces.
As a core requirement of COS202: Computer Programming II, understanding these Interfaces is vital
for efficient data manipulation.
This paper discusses the transition from the legacy Enumeration to the modernized Iterator, exploring
their syntax, algorithmic logic, and fail-fast behaviors. The study concludes with a comparative analysis
and practical applications in software development.
INTRODUCTION
In object-oriented programming, particularly in Java, a Collection is an architecture for storing and
manipulating a group of objects. However, accessing these objects without exposing the internal
structure of the collection (like an array or a linked list) requires an abstraction layer.
This is where Cursors come in. The Java API provides three main cursors: Enumeration, Iterator, and
List Iterator. For the purpose of this assignment, we focus on the two primary interfaces used for
sequential access.
While Enumeration was the standard in Java 1.0, the introduction of the Iterator in Java 1.2
revolutionized how developers interact with data by providing a unified, safer, and more functional
approach to element traversal.
DISCUSSION
A. Meaning and Definitions
Enumeration Interface: This is one of the oldest interfaces in Java. It is used to retrieve elements from
legacy collections like Vector, Stack, and Hash table. It is considered a "read-only" cursor because it
cannot modify the collection during traversal.
Iterator Interface: A more powerful successor to Enumeration. It is available for any object that
implements the Collection interface. Its primary improvement is the ability to remove elements during
iteration without causing a crash.
B. Implementation and Syntax
To use an Iterator, we must import the [Link] package. The general syntax for obtaining an iterator is:
Iterator<Type> name = [Link]();
Java Code Example: Implementation of Iterator
Java
import [Link];
import [Link];
public class MIU_Assignment {
public static void main(String[] args) {
// Creating a dynamic list of Computer Science courses
ArrayList<String> courses = new ArrayList<>();
[Link]("COS202");
[Link]("MTH202");
[Link]("GST211");
[Link]("COS204");
[Link]("Original List: " + courses);
// Obtaining the Iterator
Iterator<String> courseIterator = [Link]();
// The Algorithm: hasNext() checks for data, next() retrieves it
[Link]("Iterating through courses:");
while ([Link]()) {
String currentCourse = [Link]();
// Logic: Remove 'GST211' from the list during iteration
if ([Link]("GST211")) {
[Link]();
[Link]("-> Removed GST211 from list.");
} else {
[Link]("Course: " + currentCourse);
}
[Link]("Updated List: " + courses);
}
}
Comparison Table (The Differences)
To distinguish between the two concepts, the following table summarizes their characteristics:
Feature Enumeration Iterator Introduced In Java 1.0 (Legacy) Java 1.2 (Modern)
Methods hasMoreElements(), nextElement() hasNext(), next(), remove()
Modification Read-only; cannot remove elements. Read-write; can remove elements.
Legacy Support Only for Vector, Hash table, Stack. Works for all Collection classes.
Performance Slightly faster due to fewer checks. Preferred due to "Fail-Fast" safety.
Algorithms behind the Concept
The underlying algorithm for both concepts follows a Pointer/Cursor Logic:
A cursor is initialized before the first element (index -1).
The hasNext() or hasMoreElements() method checks if the cursor's current position is less than the size
of the collection.
The next() method moves the cursor forward by one position and returns the object at that index.
In Iterator, the remove() method targets the element last returned by next() and safely adjusts the
collection’s internal size.
Difference between Iterator and Enumerator
Iterator and Enumerator are both used to move through elements in a collection, but they differ in functionality
and modern usage.
An iterator is part of the modern Java Collections Framework and provides more control when traversing a
collection. It allows a programmer not only to read elements but also to safely remove elements during traversal
using its built-in method. Because of this flexibility and safety, iterator is widely used in current Java
programming.
An enumerator, on the other hand, is an older interface mainly associated with legacy classes such as Vector. It
allows only sequential access to elements and does not support removing elements while traversing. This makes
it less flexible compared to an iterator.?
Another key difference is that iterator is designed to work with most modern collection classes, while
enumerator is limited to older collection types. For this reason, iterator is generally preferred in modern Java
applications.
IMPORTANCE / AREAS OF APPLICATION
Memory Management: Instead of copying a whole list into a for-each loop, an Iterator moves through
the existing memory addresses, saving RAM in large-scale applications.
Thread Safety (Fail-Fast): Iterators are designed to throw a Concurrent Modification Exception if the
collection is changed by another thread while the iterator is running. This prevents data corruption.
Database Systems: When fetching thousands of rows from a database (ResultSets), Java uses iterator-
like patterns to stream data rather than loading it all at once.
Generic Programming: It allows developers to write one method that can process a Set, a List, or a
Queue interchangeably because they all use the same Iterator interface.
Other areas of Applications includes;
Database record traversal
Menu/list navigation systems
Data processing programs
Collection management
Real-time data iteration
CONCLUSION
In conclusion, while Enumeration remains part of Java for backward compatibility with legacy systems,
the Iterator interface is the superior choice for modern application development. For a student in
COS202, mastering these concepts is fundamental to understanding the Java Collections Framework and
writing robust, error-free code that handles data traversal efficiently.
REFERENCES
[1] Oracle Corporation, “Iterator (Java SE 17 & JDK 17),” Java Platform, Standard Edition v17 API
Specification, 2021. [Online]. Available:
[Link]
[2] W. Collins, Data Structures and the Java Collections Framework, rev. ed. New York, NY, USA:
McGraw-Hill Higher Education, 2004.
[3] J. Bloch, Effective Java, 3rd ed. Boston, MA, USA: Addison-Wesley, 2018.
[4] H. M. Deitel and P. J. Deitel, Java How to Program, Early Objects, 11th ed. New York, NY, USA:
Pearson, 2017.
[5] GeeksforGeeks, “Iterators in Java,” 2023. [Online]. Available:
[Link]
[6] W3Schools. “Java Enums.” [Link], 2019, [Link]/java/java_enums.asp.