java using list remove it is not the same as the other one -


so i'm super stuck. have list of students fname lname snum etc. i'm trying use remove function , doesn't work. can't figure out problem is.

public void removestudent(long snumber) {     //create student object     student student = new student();     //loop through students      (int = 0; < this.students.size(); i++) {         //display students         system.out.println(this.students.get(i));         //condition if snumber == snumber          if(student.getsnumber() == snumber){             //remove student list             this.students.remove(student);             system.out.println(this.students.get(i));         }         system.out.println("skipped if statement");     }     /*for(student student : this.students){         if(student.getsnumber() == snumber){             this.students.remove(student);         }     }*/ } 

this call method

case 3:             // delete student             system.out.print("what students snumber: s");             long snum = input.nextlong();             student chksnum = new student();             registry.getstudentbysnumber(snum);             chksnum.setsnumber(snum);             if (registry.getstudentbysnumber(snum) == chksnum) {                 if (chksnum.getsnumber() == snum) {                     registry.removestudent(snum);                     system.out.println(chksnum);                 }             } else {                 system.out.println("sorry no matches");                 // system.out.println(snum);                 system.out.println(registry.getstudentbysnumber(snum));                 system.out.println(chksnum);             }             break; 

my add student method works fine.

    public void addstudent(student student) {     this.lastsnumber++;     student.setsnumber(this.lastsnumber);     this.students.add(student); } 

if(student.getsnumber() == snumber) 

is comparing number newly constructed, blank student object. if want compare ones you're iterating over, you'll need this:

if(this.students.get(i).getsnumber() == snumber) {     this.students.remove(i); } 

Comments