File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Collections heirarchy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collections heirarchy" Watch "Collections heirarchy" New topic

Collections heirarchy

Glenny Dsilva
Ranch Hand

Joined: May 09, 2005
Posts: 42
I am creating a program to store Categories and SubCategories

like main category is having subcategories and each subcategory can have subcategories like a heirarchy.

Main Category1
| |
Sub Category1 Sub Category 2
Sub Category 1a

I want to store this heirarchy structure in a collection can anybody explain which type of collection to use and how will i retrieve the collection.

dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134

With my understanding about your problem statement i suggest you can use HashMaps where a Key,Value pair could be <MainCategory,SubCategory> Where the SubCategory is of type HashMap. That means you will result in something like this.


like this. Still not clear. Take a look at this snippet.

I agree. Here's the link:
subject: Collections heirarchy
It's not a secret anymore!