Simple java solution using treemap
\nclass Solution {\n    public List<List<String>> displayTable(List<List<String>> orders) {\n       List<List<String>> res = new ArrayList<>();\n        TreeMap
```\nclass Solution {\n    public List<List<String>> displayTable(List<List<String>> orders) {\n       List<List<String>> res = new ArrayList<>();\n        TreeMap<String,String> header= new TreeMap(); // for sorted order\n        TreeMap<String,TreeMap<String, String>> tables = new TreeMap<>((o1, o2) -> Integer.valueOf(o1).compareTo(Integer.valueOf(o2))); //  default is lex compare, change to int\n\n        for(List<String> order : orders) {\n            header.put(order.get(2), "0");\n        }\n\n        for(List<String> order : orders) {\n            tables.put(order.get(1), new TreeMap(header));\n        }\n       \n\n        for(List<String> order: orders) {\n            TreeMap<String, String> items = tables.get(order.get(1));\n            String item = String.valueOf(Integer.parseInt(items.get(order.get(2))) + 1);\n            items.put(order.get(2),item);\n            tables.put(order.get(1), items);\n        }\n\n\n        List<String> resHeader = new ArrayList(header.keySet());\n        resHeader.add(0, "Table");\n        res.add(resHeader);\n\n        for(String table:tables.keySet()) {\n            List<String> itemsRow = new ArrayList();\n            for(String item:tables.get(table).keySet()) {\n                itemsRow.add(tables.get(table).get(item));\n            }\n            itemsRow.add(0,table);\n            res.add(itemsRow);\n        }\n\n\n        return res;\n    }\n}\n```
['Tree', 'Java']