For the record, I don't have allot of Java experience. If I understand correctly, you are trying to validate the contents of several TextFields in a GUI. And the validation only makes certain that the textfield is empty. I would recommend that instead of using a collection of the textField names, you simply use a collection of references to the textfields you wish to validate.
So your ArrayList is populated with textfield references instead:
ArrayList<TextField> textFields = new ArrayList<TextField>();
textFields.add(textbox1);
textFields.add(textbox2);
textFields.add(textbox3);
textFields.add(textbox4);
You iterate through the ArrayList like before. I used a System.Out call for my own testing.:
for(TextField textField : textFields) {
if(validateTextField(textField)) {
//JOptionPane.showMessageDialog(null, textField.getText() + " Empty value");
System.out.println(textField.getName() + " has an Empty value");
}
}
The validate function now looks like this. I added a test for a NULL reference, but you could leave that out.:
public static boolean validateTextField(TextField textField) {
if(textField == null) throw new NullPointerException("The validate function received a null textfield reference. Check your loop.");
return textField.getText().length() == 0;
}