removing element from a list
Hello i would like to know how to remove an element for exemple a personne from a list, if his name is on the list. The name of the person is furnish dynamically for exemple through a jsp page. I would like to know how to compare the name furnish with the list of person and if the name provided via the jsp is corresponding to someone in the list, i remove this person from the list.
Thanks for help.
Message was edited by:
JusteUneQuestion
# 1
E.g. ...
List lp = ...;
String nameGiven = ...;
for (Iterator it = lp.iterator();it.hasNext();) {
if (((Person) it.next()).getName().equals(nameGiven)) {
it.remove();
break;
}
}
Though I guess I'd understand the problem better if it was described in French ...
# 6
> 1) Iterate over list2 and get name.
> 2) For each name, call list1.contains(<name>)
> 3) If it returns true, then call list2.remove(<name>)
Yes that is right, i used it as first, but it didnt work cause i didnt redefine equals and hashCode() for my object so contains() never return anything correct. Now i redefine those method and it works fine this way.