Title of Assignment: Student Record Management using Collection Framework: Implement a Java
program using ArrayList, Hash-Map, and Iterator to store, search, update, and display student records.
Aim:To implement a Java program using the Collection Framework (ArrayList, HashMap, and
Iterator) to store, search, update, delete, and display student records efficiently.
2. Objectives-After completing this experiment, students will be able to:
Understand the Java Collection Framework.
Use ArrayList to store student records dynamically.
Use HashMap for fast searching using roll numbers.
Traverse collection elements using Iterator.
Perform CRUD (Create, Read, Update, Delete) operations on student records.
Develop menu-driven Java applications using collection classes.
3. Problem Definition:Design and implement a Student Record Management System using
Java Collection Framework. The program should use:
ArrayList for storing student records.
HashMap for quick searching of records using Roll Number.
Iterator for displaying all student records.
The system should perform the following operations:
Add Student Record
Display Student Records
Search Student by Roll Number
Update Student Record
Delete Student Record
4. Prerequisites
Students should have knowledge of:
Basics of Java Programming
Object-Oriented Programming Concepts
Java Collection Framework
ArrayList
HashMap
5. Software Requirements
Software Requirement
Operating System Windows 10/11
Programming Language Java
JDK Version JDK 8 or above
IDE VS Code
Compiler javac
Package Used [Link].*
Theory
Java Collection Framework
The Java Collection Framework (JCF) is a unified architecture that provides classes and
interfaces to store, manipulate, and retrieve groups of objects dynamically. It simplifies
programming by providing ready-made data structures and algorithms.
Advantages
Dynamic memory allocation
Better performance
Easy searching
Easy insertion and deletion
Reusable code
Standard API
ArrayList
Definition
ArrayList is a dynamic array implementation of the List interface that allows elements to grow
and shrink dynamically.
Features
Dynamic size
Maintains insertion order
Allows duplicate elements
Fast random access
Stores objects only
Common Methods
add()
get()
set()
remove()
contains()
size()
Syntax
ArrayList<Student> list = new ArrayList<>();
HashMap
Definition
HashMap stores data in key-value pairs. It provides fast searching using a unique key.
Features
Stores unique keys
Allows one null key
Does not maintain insertion order
Fast lookup operations
Efficient searching
Common Methods
put()
get()
containsKey()
remove()
keySet()
values()
Syntax
HashMap<Integer, Student> map = new HashMap<>();
Iterator
Definition
An Iterator is an interface used to traverse the elements of a collection one at a time.
Advantages
Safe traversal
Easy access to collection elements
Supports removal during traversal
Methods
hasNext()
next()
remove()
Syntax
Iterator<Student> itr = [Link]();
while([Link]())
{
[Link]([Link]());
}
Scanner Class
The Scanner class is used to accept input from the keyboard.
Syntax
Scanner sc = new Scanner([Link]);
Algorithm
1. Start the program.
2. Create a Student class.
3. Create an ArrayList to store student objects.
4. Create a HashMap using Roll Number as the key.
5. Display the menu.
6. Read the user's choice.
7. Perform one of the following operations:
o Add Student
o Display Students
o Search Student
oUpdate Student
oDelete Student
8. Repeat the menu until the user chooses Exit.
9. Stop the program.
Viva Questions
1. What is the Java Collection Framework?
2. What is the difference between Array and ArrayList?
3. What is a HashMap?
4. Why is HashMap faster for searching?
5. What is an Iterator?
6. What is the difference between ArrayList and LinkedList?
7. Can HashMap store duplicate keys?
8. What is the time complexity of searching in HashMap?
9. What is the purpose of the toString() method?
10. Why is the Collection Framework preferred over arrays?
JAVA CODE:
import [Link].*;
class Student {
int id;
String name;
int age;
String course;
Student(int id, String name, int age, String course) {
[Link] = id;
[Link] = name;
[Link] = age;
[Link] = course;
}
public String toString() {
return "ID: " + id +
", Name: " + name +
", Age: " + age +
", Course: " + course;
public class StudentRecordManagement {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
ArrayList<Student> studentList = new ArrayList<>();
HashMap<Integer, Student> studentMap = new HashMap<>();
int choice;
do {
[Link]("\n===== Student Record Management =====");
[Link]("1. Add Student");
[Link]("2. Search Student");
[Link]("3. Update Student");
[Link]("4. Display All Students");
[Link]("5. Exit");
[Link]("Enter your choice: ");
choice = [Link]();
switch (choice) {
case 1:
[Link]("Enter ID: ");
int id = [Link]();
[Link]();
if ([Link](id)) {
[Link]("Student ID already exists!");
break;
[Link]("Enter Name: ");
String name = [Link]();
[Link]("Enter Age: ");
int age = [Link]();
[Link]();
[Link]("Enter Course: ");
String course = [Link]();
Student s = new Student(id, name, age, course);
[Link](s);
[Link](id, s);
[Link]("Student added successfully.");
break;
case 2:
[Link]("Enter Student ID to Search: ");
int searchId = [Link]();
if ([Link](searchId)) {
[Link]([Link](searchId));
} else {
[Link]("Student not found.");
break;
case 3:
[Link]("Enter Student ID to Update: ");
int updateId = [Link]();
[Link]();
if ([Link](updateId)) {
Student st = [Link](updateId);
[Link]("Enter New Name: ");
[Link] = [Link]();
[Link]("Enter New Age: ");
[Link] = [Link]();
[Link]();
[Link]("Enter New Course: ");
[Link] = [Link]();
[Link]("Student record updated.");
} else {
[Link]("Student not found.");
break;
case 4:
if ([Link]()) {
[Link]("No student records available.");
} else {
[Link]("\nStudent Records:");
Iterator<Student> iterator = [Link]();
while ([Link]()) {
[Link]([Link]());
break;
case 5:
[Link]("Exiting...");
break;
default:
[Link]("Invalid choice!");
} while (choice != 5);
[Link]();
OUTPUT:
PS F:\> javac [Link]
PS F:\> java StudentRecordManagement
===== Student Record Management =====
1. Add Student
2. Display Students
3. Search Student
4. Update Student
5. Delete Student
6. Exit
Enter Choice: 1
Enter Roll No: 1
Enter Name: rani
Enter Age: 22
Enter Course: co
Student Added Successfully.
===== Student Record Management =====
1. Add Student
2. Display Students
3. Search Student
4. Update Student
5. Delete Student
6. Exit
Enter Choice: 1
Enter Roll No: 2
Enter Name: yogita
Enter Age: 23
Enter Course: it
Student Added Successfully.
===== Student Record Management =====
1. Add Student
2. Display Students
3. Search Student
4. Update Student
5. Delete Student
6. Exit
Enter Choice: 3
Enter Roll No to Search: 2
Roll No: 2, Name: yogita, Age: 23, Course: it
===== Student Record Management =====
1. Add Student
2. Display Students
3. Search Student
4. Update Student
5. Delete Student
6. Exit
Enter Choice: 2
Student Records
Roll No: 1, Name: rani, Age: 22, Course: co
Roll No: 2, Name: yogita, Age: 23, Course: it
===== Student Record Management =====
1. Add Student
2. Display Students
3. Search Student
4. Update Student
5. Delete Student
6. Exit
Enter Choice: 4
Enter Roll No to Update: 1
Enter New Name: sayali
Enter New Age: 24
Enter New Course: it
Record Updated.
===== Student Record Management =====
1. Add Student
2. Display Students
3. Search Student
4. Update Student
5. Delete Student
6. Exit
Enter Choice: 1
Enter Roll No: 3
Enter Name: payal
Enter Age: 21
Enter Course: co
Student Added Successfully.
===== Student Record Management =====
1. Add Student
2. Display Students
3. Search Student
4. Update Student
5. Delete Student
6. Exit
Enter Choice: 2
Student Records
Roll No: 1, Name: sayali, Age: 24, Course: it
Roll No: 2, Name: yogita, Age: 23, Course: it
Roll No: 3, Name: payal;, Age: 21, Course: co
===== Student Record Management =====
1. Add Student
2. Display Students
3. Search Student
4. Update Student
5. Delete Student
6. Exit
Enter Choice: 6
Program Ended.
PS F:\>
Conclusion
The Student Record Management System was successfully implemented using the Java
Collection Framework. The program utilized ArrayList for dynamic storage of student
records, HashMap for efficient searching and retrieval using roll numbers, and Iterator for
traversing and displaying the records. The application successfully performed all CRUD
operations—Create, Read, Update, and Delete—through a menu-driven interface. This
experiment demonstrates the practical use of Java collections to develop efficient, flexible,
and maintainable applications for managing data