Worksheet-2.3 Java PDF
Worksheet-2.3 Java PDF
Experiment- 2.3
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 : This program aims to create a string list manager, allowing users to insert,
delete, display, and search for specific strings within the list. This provides a basic framework
for manipulating and organizing string data.
3. Procedure :
1. ArrayList and Scanner: The program uses an ArrayList to store items and a Scanner to read user
input.
2. Menu Display: A menu is continuously displayed to the user until they choose to exit. The menu
includes options to insert, search, delete, display items, and exit the program.
3. Switch Statement: Depending on the user’s choice, different operations are performed. This is
managed using a switch statements.
4. Insert Operation: If the user chooses to insert an item, they are prompted to enter the item. The item is
then added to the ArrayList.
5. Search Operation: If the user chooses to search for an item, they are prompted to enter the item. The
program then checks if the item exists in the ArrayList.
6. Delete Operation: If the user chooses to delete an item, they are prompted to enter the item. The
program then attempts to remove the item from the ArrayList
7. Display Operation: If the user chooses to display the items, the program prints all the items in the
ArrayList.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Program Code :
import java.util.ArrayList;
import java.util.Scanner;
break;
case 4:
System.out.println("The Items in the list are : ");
for (String str : list) {
System.out.println(str);
}
break;
case 5:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice! Please enter a valid option.");
}
} while (choice != 5);
scanner.close();
}
}
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :