java - How to remove an object from an ArrayList? -
i want remove object arraylist based on students name , each object has 5 elements. question: how remove object text file.
arraylist<student> studentlist= new arraylist<student>(); iterator iter = studentlist.iterator(); public dvd remove(string removename) { while (iter.hasnext()) { (student stu : studentlist) { if (stu .getname().touppercase().contains(removename.touppercase())) { system.out.println("found , removed"); iter.remove(); return stu ; } system.out.println("not found"); } } return null; }
each student read in text file. 1 element per line.
ex:
john smith undergrad 21 years old 2010 2014 pocahantas professor 369 years old 1599 1603 etc... // new person etc....
i don't think need iterator:
public student remove(string removename) { (student stu : studentlist) { if (stu.getname().touppercase().contains(removename.touppercase())) { system.out.println("found , removed"); studentlist.remove(stu); return stu; } } system.out.println("not found"); return null; }
Comments
Post a Comment