How to create/traverse a multi-demintional arraylist or list?
-
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>>… would work for x and y but doesnt work for z because z is only 2 levels down. I would appreciate some tips on how to do this. I understand that what im 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).
-
Answer:
Any time you start putting library types inside library types inside library types, reconsider the design of your program. Maybe add some classes in lieu of the cascading ArrayLists you have right now. You admit that you should be using a tree instead. Java supports Trees (TreeModel http://docs.oracle.com/javase/6/docs/api/javax/swing/tree/TreeModel.html) Because right now, the way you have it organized, I can't even understand what you're trying to do. It seems very convoluted, when what you want to do is actually quite simple.
jiejiewu at Yahoo! Answers Visit the source
Related Q & A:
- How to create expandable list?Best solution by Stack Overflow
- How to programatically select a item in list using c#?Best solution by Software Quality Assurance & Testing
- How can I remove a contact from a list in my address book?Best solution by windows.microsoft.com
- How do I add a sender to my safe list?Best solution by Yahoo! Answers
- How to create a private distribution list?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.