Java map
\nclass Solution {\n    public List<List<String>> displayTable(List<List<String>> orders) {\n        Set<String> items = new TreeSet<>();\n        List<List<Str
```\nclass Solution {\n    public List<List<String>> displayTable(List<List<String>> orders) {\n        Set<String> items = new TreeSet<>();\n        List<List<String>> ans = new ArrayList<>();\n        Map<Integer,Map<String,Integer>> res = new TreeMap<>();\n        for(int i=0;i<orders.size();i++){\n            List<String> cur = orders.get(i);\n            int tn = Integer.parseInt(cur.get(1));\n            items.add(cur.get(2));\n            if(res.containsKey(tn)){\n                Map<String,Integer> kk = res.get(tn);\n                kk.put(cur.get(2) , kk.getOrDefault(cur.get(2),0)+1);\n            } else{\n                Map<String,Integer> kk = new HashMap<>();\n                kk.put(cur.get(2),1);\n                res.put(tn,kk);\n            }\n        }\n        List<String> oo = new ArrayList<>();\n        oo.add("Table");\n        for(String i : items){\n            oo.add(i);\n        }\n        ans.add(oo);\n        for(Map.Entry<Integer,Map<String,Integer>> pp : res.entrySet()){\n            int tn = pp.getKey();\n            List<String> med = new ArrayList<>();\n            med.add(String.valueOf(tn));\n            Map<String,Integer> pl = pp.getValue();\n            for(String i:items){\n                med.add(String.valueOf(pl.getOrDefault(i,0)));\n            }\n            ans.add(med);\n        }\n        return ans;\n    }\n}\n```
[]