I have a list of strings and I have 10 unique methods doing different validations based on what string it is. For example this is what I have now:
if(name1 != null){
validateName1();
}
else{
throw Error();
}
if(name2 != null){
validateName2();
}
else{
throw Error();
}
...
So instead of doing the same if-else check 10 times for all the different methods I was hoping I could store the names in a String list and have a for loop going through it in the following manner:
List<String> names = new ArrayList<String>();
for(name : names){
if(name != null){
validate[name]();
}
else{
throw Error();
}
Please let me know if this is possible, or if this is a rudimentary approach and there is a more elegant solution to my problem. To reiterate my problem is basically I have 10 different & unique validate methods and instead of writing if-else for each of them I want to be able to go through a for loop to call these methods with the new name.
Thanks in advance for the help!
array[i].method(value);