Easy Java Solution || HashMap
Hi, Please Upvote if it is helpful.\n\nclass Solution {\n    public List<List<String>> displayTable(List<List<String>> orders) {\n        List<List<String>> ans
Hi, Please Upvote if it is helpful.\n```\nclass Solution {\n    public List<List<String>> displayTable(List<List<String>> orders) {\n        List<List<String>> ans = new ArrayList<>();\n        List<String> head = new ArrayList<>();\n        head.add("Table");\n        Map<Integer, Map<String,Integer>> map = new TreeMap<>();\n        for(List<String> s: orders){\n            if(!head.contains(s.get(2))) head.add(s.get(2));\n            int tbl = Integer.parseInt(s.get(1));\n            map.putIfAbsent(tbl, new TreeMap<>());\n            if(map.get(tbl).containsKey(s.get(2))){\n                Map<String, Integer> m = map.get(tbl);\n                m.put(s.get(2), m.getOrDefault(s.get(2), 0)+1);\n            }else{\n                map.get(tbl).put(s.get(2), 1);\n            }\n        }\n        String[] arr = head.toArray(new String[0]);\n        Arrays.sort(arr, 1, head.size());\n        head = Arrays.asList(arr);\n        ans.add(head);\n        \n        for(Map.Entry<Integer, Map<String, Integer>> entry: map.entrySet()){\n            List<String> l = new ArrayList<>();\n            l.add(entry.getKey() + "");\n            Map<String,Integer> m = entry.getValue();\n            for(int i=1; i<arr.length; i++){\n                if(m.containsKey(arr[i])){\n                    l.add(m.get(arr[i])+"");\n                }else{\n                    l.add("0");\n                }\n            }\n            ans.add(l);\n        }\n        System.out.print(map);\n        return ans;\n    }\n}\n```
['Java']