0% found this document useful (0 votes)
2 views

Java Exp-4 akshat (1)

The document outlines an experiment for a computer science course where students implement basic operations (insert, delete, display, and search) on a list of String objects in Java. It includes the aim, objectives, implementation code, and expected learning outcomes related to CRUD operations using ArrayList and user interaction. The program allows users to manage a list through a console interface until they choose to exit.

Uploaded by

Akshat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java Exp-4 akshat (1)

The document outlines an experiment for a computer science course where students implement basic operations (insert, delete, display, and search) on a list of String objects in Java. It includes the aim, objectives, implementation code, and expected learning outcomes related to CRUD operations using ArrayList and user interaction. The program allows users to manage a list through a console interface until they choose to exit.

Uploaded by

Akshat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

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;

public class StringListOperations {

private static ArrayList<String> list = new ArrayList<>();

public static void insertItem(String item) {


list.add(item);
}

public static void deleteItem(String item) {


if (list.contains(item)) {
list.remove(item);
System.out.println(item + " has been removed.");
} else {
System.out.println(item + " not found in the list.");
}
}

public static void displayList() {


if (list.isEmpty()) {
System.out.println("The list is empty.");
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
} else {
System.out.println("List items: " + list);
}
}

public static void searchItem(String item) {


if (list.contains(item)) {
System.out.println(item + " is found in the list.");
} else {
System.out.println(item + " is not found in the list.");
}
}

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
int choice;

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.

You might also like