Count Items Matching a Rule || Java || 100% faster || Easy.
Two ways to do that . This is the first way :\n\nclass Solution {\n    public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {\n  
## Two ways to do that . This is the first way :\n```\nclass Solution {\n    public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {\n        // Number of items that match the given rule\n        int count = 0;\n        \n        // Get the index of ruleKey \n        int index;\n        if (ruleKey.equals("type"))\n            index = 0;\n        else if (ruleKey.equals("color"))\n            index = 1;\n        else\n            index = 2;\n            \n        \n        \n        // Go through every items\n        for (List<String> item : items){ \n            \n            if (item.get(index).equals(ruleValue)) count++;\n        }\n        \n        return count;\n    }\n}\n\n```\n\n## Second way :\n\n```\nclass Solution {\n    public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {\n        // Number of items that match the given rule\n        int count = 0;\n        \n        for (List<String> item : items){\n            if (ruleKey.equals("type") && item.get(0).equals(ruleValue)) count++;\n            if (ruleKey.equals("color") && item.get(1).equals(ruleValue)) count++;\n            if (ruleKey.equals("name") && item.get(2).equals(ruleValue)) count++;\n        }\n        \n        return count;\n    }\n}\n```
['Array', 'Java']