Vấn đề khi sửa object trong list - Java

Góp ý em cái mọi người!
Chức năng sửa của em khi sửa thì vẫn thành công, nhưng khi hiển thị thì nó lại không sửa trực tiếp object đã có trong list.

public void cN2(List<Personnel> list) {
    System.out.println("Nhap ma so :");
    String maSo = sc.nextLine();
    Iterator<Personnel> iD = list.iterator();
    int index = 0;
    while (iD.hasNext()) {
        Personnel epl = iD.next();
        if (epl.getMaSo().equals(maSo)) {
            System.out.println("Nhap ten moi :");
            String newTen = sc.nextLine();
            System.out.println("Nhap ngay sinh moi :");
            String newNgaySinh = sc.nextLine();
            System.out.println("Nhap gioi tinh moi :");
            String newGioiTinh = sc.nextLine();
            System.out.println("Nhap ngay lam moi :");
            String newNgayLam = sc.nextLine();
            System.out.println("Nhap quoc tich moi :");
            String newQuocTich = sc.nextLine();
            System.out.println("Nhap chuc vu moi :");
            String newChucVu = sc.nextLine();
            System.out.println("Nhap he so moi :");
            double newHeSo = Double.parseDouble(sc.nextLine());
            System.out.println("Nhap luong thoa thuan :");
            double newLuongThoaThuan = Double.parseDouble(sc.nextLine());
            System.out.println("Sua thanh cong");
            Personnel newEpl = new Personnel(newTen, newNgaySinh, newGioiTinh, newNgayLam, newQuocTich, maSo, newChucVu, newHeSo, newLuongThoaThuan);
            list.set(index, newEpl);
            break;
        }
    }
    index++;
}

EDIT (@library): Cậu nhớ:

  • Dùng Markdown để format code cho các post sau nhé!
  • Đặt tên topic ngắn gọn, và mô tả vấn đề của cậu trong post đầu tiên nhé!
  • Viết tiếng Việt chỉn chu nhé! :smile:
epl.setTen() = sc.nextLine();
epl.setNgaySinh() = sc.nextLine();
.
.
.

Sao k dùng set trực tiếp luôn mà new lại gì cho mệt

5 Likes

thank ban nhieu nha
hihii

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?