Lets assume that I have a class with multiple String fields.
public class Person {
private String address;
private String first_name;
//etc
Now lets say that I have a List of Persons:
List<Person>
I want to write a method that can parse this list for a specific string value, e.g. address=="California".
The problem is that I have multiple fields in this class and it would be a lot of code reuse if I make a method for each field.
I could also do:
public List<Person> filter(List<Person> plist, String fieldToParse, String value){
//simple loop that removes the Person.fieldToParse == Person.value values
}
But is there a simpler, less ugly way for me to do this?