Skip to main content
1 of 3
cody.codes
  • 2k
  • 2
  • 26
  • 45

Finding all plurals in an array of Strings

Looking for feedback on this here code. Is readability an issue? Is it good to mess with all these data types in Java (e.g. strings and Chars and using .equals() and != to compare data from different datatypes), or is there an easier way to do it? And in general, how can I improve this code?

Problem Description

   public static boolean allPlural(String[] words){
        for (String s : words) {
            // blank string is not plural
            if (s.equals("")) {
                return false;
            }
            // if the strings in the array don't have an s on the end, return false
            if (Character.toUpperCase(s.charAt(s.length()-1)) != 'S') {
                return false;
            }
        }
        return true;
    }
cody.codes
  • 2k
  • 2
  • 26
  • 45