Java Exp-4 akshat (1)
Java Exp-4 akshat (1)
Experiment 4
Student Name: Akshat Shukla UID: 22BCS12484
Branch: BE-CSE Section/Group: 902_DL:B
Semester:6th Date of Performance: 12/02/2025
Subject Name: Project Based Learning Subject Code: 22CSH-359
in Java with Lab
1. Aim: Write a Program to perform the basic operations like insert, delete,
display and search in list. List contains String object items where these
operations are to be performed.
2. Objective: The objective of this program is to implement basic operations
(insert, delete, display, and search) on a List containing String objects. The
program will demonstrate how to manipulate a list using common list
operations in Java, providing functionality to manage and interact with data
stored in the list.
3. Implementation/Code:
import java.util.ArrayList;
import java.util.Scanner;
do {
System.out.println("\nSelect an operation:");
System.out.println("1. Insert Item");
System.out.println("2. Delete Item");
System.out.println("3. Display List");
System.out.println("4. Search Item");
System.out.println("5. Exit");
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.print("Enter item to insert: ");
String insertItem = sc.nextLine();
insertItem(insertItem);
break;
case 2:
System.out.print("Enter item to delete: ");
String deleteItem = sc.nextLine();
deleteItem(deleteItem);
break;
case 3:
displayList();
break;
case 4:
System.out.print("Enter item to search: ");
String searchItem = sc.nextLine();
searchItem(searchItem);
break;
case 5:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
System.out.println("Exiting program.");
break;
default:
System.out.println("Invalid choice! Please choose a valid option.");
}
} while (choice != 5);
sc.close();
}
}
4. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Learning Outcomes:
1. Learn how to perform basic CRUD (Create, Read, Update, Delete) operations
on a List of String objects in Java.
2. Understand how to use the ArrayList class for dynamically storing and
manipulating a collection of items.
3. Practice handling user input using the Scanner class for interaction with the
program.
4. Implement methods for searching, deleting, and displaying items in a list
efficiently.
5. Gain familiarity with control flow and loops to allow for continuous user
interaction until the program is exited.