Ex.
13 Program implementing ArrayList
Source Code
import [Link];
import [Link];
public class StudentList
{
public static void main(String[] args)
{
ArrayList<String> students = new ArrayList<>();
Scanner scanner = new Scanner([Link]);
// Adding students to the ArrayList
[Link]("Enter student names (type 'stop' to finish):");
while (true)
{
[Link]("Enter student name: ");
String name = [Link]();
if ([Link]("stop"))
break;
// Add student to the list
[Link](name);
}
// Display the list of students
[Link]("\nList of students:");
for (String st : students)
[Link](st);
// Remove a student by name
[Link]("\nEnter the name of the student to remove: ");
String studentToRemove = [Link]();
if ([Link](studentToRemove))
[Link](studentToRemove + " has been removed.");
else
[Link](studentToRemove + " was not found in the list.");
// Display the updated list of students
[Link]("\nUpdated list of students:");
for (String st : students)
[Link](student);
[Link]();
}
}