I have 6 words that is stored in a HashSet
as below :
String first = jtfFirstWord.getText();
String second = jtfSecondWord.getText();
String third = jtfThirdWord.getText();
String fourth = jtfFourthWord.getText();
String fifth = jtfFifthWord.getText();
String sixth = jtfSixthWord.getText();
Set<String> accept = new HashSet<String>(Arrays.asList(new String[] {first,second,third,fourth,fifth,sixth}));
I want to check if the length of all words is not 7, 9, or 11, then I will prompt users with a message box to warn them to only enter 7, 9, or 11-characters word.
Currently, I'm using if-else statement to manually check the condition like:
if (first.length() != 7 || first.length() != 9 || first.length() != 11 ||
second.length() != 7 ||second.length() != 9 || second.length() != 11 ||
... and it continues until the sixth word.
By using this way, it reduce my code readability and its not an elegant way of checking user inputs.
My question is how do I check the length of the String element stored previously in the HashSet shown above? Or is there any other elegant and efficient way of checking the inputs?