public static void RemoveStudent(ArrayList<InforStudent> ifst) {
Scanner s = new Scanner(System.in);
System.out.println("nhập mã sv muốn xóa: ");
String keyWordsRemove = s.nextLine();
for (int i = 0; i < ifst.size(); i++) {
if (ifst.get(i).getMaSV().equals(keyWordsRemove)) {
ifst.remove(ifst.get(i).getTen());
ifst.remove(ifst.get(i).getMaSV());
ifst.remove(ifst.get(i).getHoTenDem());
ifst.remove(ifst.get(i).getGioiTinh());
ifst.remove(ifst.get(i).getNgaySinh());
System.out.println("Đã xóa: " + keyWordsRemove);
}else System.out.println("Không tìm thấy dữ liệu cần xóa");
}
}
InforStudent.java
import java.io.Serializable;
public class InforStudent implements Serializable {
String maSV;
String hoTenDem;
String ten;
String ngaySinh;
String gioiTinh;
public String getMaSV() {
return maSV;
}
public void setMaSV(String maSV) {
this.maSV = maSV;
}
public String getHoTenDem() {
return hoTenDem;
}
public void setHoTenDem(String hoTenDem) {
this.hoTenDem = hoTenDem;
}
public String getTen() {
return ten;
}
public void setTen(String ten) {
this.ten = ten;
}
public String getNgaySinh() {
return ngaySinh;
}
public void setNgaySinh(String ngaySinh) {
this.ngaySinh = ngaySinh;
}
public String getGioiTinh() {
return gioiTinh;
}
public void setGioiTinh(String gioiTinh) {
this.gioiTinh = gioiTinh;
}
public InforStudent() {
}
public InforStudent(String maSV, String hoTenDem, String ten, String ngaySinh, String gioiTinh) {
this.maSV = maSV;
this.hoTenDem = hoTenDem;
this.ten = ten;
this.ngaySinh = ngaySinh;
this.gioiTinh = gioiTinh;
}
}
em muốn xóa dữ liệu trong Arraylist mà sao không xóa được ai đó giúp em với.