I have a array list in which I bind the data This is a example
MyStrings =new ArrayList();
MyStrings.add(\"Dog\");
MyStrings.add(\"Cat\");
MyString
You can use the apache commons-collections library as well:
CollectionUtils.filter(myStrings,
new Predicate() {
public boolean evaluate(Object o) {
return ! ((String)o).startsWith("c");
}
}
};
Any object for which the "evaluate" method of the Predicate class returns false is removed from the collection. Keep in mind, that like the solution above using the Iterator, this is destructive to the list it is given. If that is an issue, you can always copy the list first:
List filtered = new ArrayList(myStrings);
CollectionUtils.filter(filtered, ...);