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

Ex 13 Java

java program

Uploaded by

TRANAND TR
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)
13 views

Ex 13 Java

java program

Uploaded by

TRANAND TR
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/ 2

Ex.

13 Program implementing ArrayList

Source Code
import java.util.ArrayList;
import java.util.Scanner;

public class StudentList


{
public static void main(String[] args)
{
ArrayList<String> students = new ArrayList<>();
Scanner scanner = new Scanner(System.in);

// Adding students to the ArrayList


System.out.println("Enter student names (type 'stop' to finish):");
while (true)
{
System.out.print("Enter student name: ");
String name = scanner.nextLine();

if (name.equalsIgnoreCase("stop"))
break;

// Add student to the list


students.add(name);
}

// Display the list of students


System.out.println("\nList of students:");

for (String st : students)


System.out.println(st);
// Remove a student by name
System.out.print("\nEnter the name of the student to remove: ");
String studentToRemove = scanner.nextLine();

if (students.remove(studentToRemove))
System.out.println(studentToRemove + " has been removed.");
else
System.out.println(studentToRemove + " was not found in the list.");

// Display the updated list of students


System.out.println("\nUpdated list of students:");

for (String st : students)


System.out.println(student);

scanner.close();
}
}

You might also like