I would like to know how to create a structure to hold three lists in the following format:
[[[x],[y]],[z]]
with x,y,z being three lists of strings.
Note that I want to have the x and y lists on the 3rd level down and the z list on the 2nd level down.
I have tried creating 3 separate arraylists for x,y and z then another arraylist that holds x and y. The problem arise when I tried to create the outer most arraylist to hold all three, because something like
ArrayList<ArrayList<ArrayList<String>>> outerList = new ArrayList<ArrayList<ArrayList<String>>>();
would work for x and y but wont work for z because z is only 2 levels down.
I understand what I’m trying to do is more like a tree but I do not know how to implement a non-binary tree in java (x,y,z having more then just 2 branches).
What I’m trying to get out of this is a way to assign weights eg. user inputs a term, I iterate first through all the child nodes (x,y,z) and try to find it. If I find it I assign a high weight, otherwise I try to find it in the parent nodes (the list that holds x,y) and give it a moderate weight else I search in the root node and assign a minimum weight. The structure described is simply the relationship between the terms that I have categorized.
Any ideas on how to do this?
The structure is easy enough to make, but working with it will be really ugly because you don’t know how deep it goes. If this is a set structure, where you only ever have x, y, and z, you should make a custom object to handle that known structure. If you won’t know the structure until runtime, then you need something like this.
Note that while this structure does match what you asked for, I don’t necessarily recommend using it unless you have to. Look for alternatives. You mentioned a tree, but from your structure this would be a tree with data only at the leaf nodes, so keep that in mind if/when you implement it.