在上面的代码中,我接受了用户输入并将其存储在要存储到文件中的列表中的列表中,因此我需要从文件中获取特定列表并从文件中删除特定列表
void delete() {
File file = new File("E://Demo1.txt");
if (file.exists()) {
System.out.println("Enter the Email you want to delete from the list");
String email = sc.next();
// this for each loop will fetch the list of all the users and check the
// condition given by the user
for (UserDetails p : al) {
if (p.getEmail().equals(email)) {
al.remove(p);
System.out.println("List is deleted");
break;
} else {
System.out.println("Entered email is not in the list");
}
}
}