Is there a way to validate a number of JTextfields in java without the if else structure. I have a set of 13 fields, i want an error message when no entry is given for any o
Here is one way to do it:
public static boolean areAllNotEmpty(String... texts) { for(String s : texts) if(s == null || "".equals(s)) return false; return true; } // ... if(areAllNotEmpty(firstName, lastName, emailAddress, phone)) { JOptionPane.showMessageDialog(null, "No data entered"); }