evergrean100
Technical User
I have a validate method that works and now I want to condense it into a for loop.
Here is what I have:
My attempt doesnt work because I cant seem to figure out how to put the array reference in the key part of the errors.put method:
The results dont validate any of my data so I assume I have something wrong with my array. Please advise.
Here is what I have:
Code:
//firstname and lastname are declared earlier
public boolean validate()
{
boolean allOk=true;
if (firstName.equals("")) {
errors.put("firstName","Please enter your first name");
allOk=false;
}
if (lastName.equals("")) {
errors.put("lastName","Please enter your last name");
allOk=false;
}
return allOk;
}
My attempt doesnt work because I cant seem to figure out how to put the array reference in the key part of the errors.put method:
Code:
public boolean validate()
{
boolean allOk=true;
String [] myarray = {firstname, lastname}
for(int i=0;i < myarray.length;i++)
{
if (myarray[i].equals("")) {
errors.put(myarray[i],"Please enter your " + myarray[i]);
allOk=false;
}
}
return allOk;
}
The results dont validate any of my data so I assume I have something wrong with my array. Please advise.