I would use Map for this purpose, because it makes it easier to find subcategories based on the main category. If you use List<List<String>> , you actually have no way to determine which main category this subcategory belongs to. Here is an example of using TreeMap (which automatically saves the main categories in alphabetical order):
Map<String, List<String>> mainCategories = new TreeMap<>(); mainCategories.put("A", Arrays.asList("A1", "A2", "A3")); mainCategories.put("B", Arrays.asList("B1", "B2")); mainCategories.put("C", Arrays.asList("C1")); System.out.println(mainCategories); System.out.println(mainCategories.get("B"));
Will print
{A = [A1, A2, A3], B = [B1, B2], C = [C1]}
[B1, B2]
source share