The title may not exactly sound. The essence is this. there is a certain List (Map), the structure of which is approximately the same

id=0; title="нулевой уровень"; parent=null id=1; title="уровень 0.1"; parent=0 id=11; title="нулевой уровень 1"; parent=null id=111; title="уровень 1.0"; parent=11 id=1111; title="нулевой уровень"; parent=111 

roughly speaking, this is a product catalog with categories. you need to somehow make alternate selection of categories. Because of my small experience in java, my approach to this issue translates into a swollen method of iterating through the entire list and adding a heap of arrays ...

    1 answer 1

    Create 2nd collections: one stores the name of the categories, the other stores the name of the goods. For example, this is how you fill out the root sheet:

     public someClass { public ArrayList initManufList() { ManufacturerList.add("Audi"); ManufacturerList.add("Skoda"); ManufacturerList.add("Volkswagen"); return ManufacturerList; } // инициализируем корневой лист public ArrayList initModelList(String str){ if(str.equals("Audi")) return initAudiList(); else if (str.equals("Skoda")) return initSkodaList(); else if (str.equals("Volkswagen")) return initVolkswagenList(); return null; } // на основе корня выбираете дочерние элементы private ArrayList initAudiList(){ AudiList.add("A1"); AudiList.add("A2"); AudiList.add("A3"); AudiList.add("A4"); return AudiList; }} 

    Well, then the logic of how to bind children to the parent.