aspose file tools*
The moose likes Java in General and the fly likes Collection of Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Collection of Collections" Watch "Collection of Collections" New topic
Author

Collection of Collections

Mc. Alvin Bautista
Greenhorn

Joined: Jul 17, 2006
Posts: 10
I have a problem of accessing a specific collection which is included inside a collection object I created. For example, I have a collection of numbers ranges 0-99,100-199,200-299,...This 0-99 is equal to one collection, So therefore I have created a Collection of Collections of numbers. What I want is, I want to get the specific collection on that Collection object. Anyone have any idea on this. Please help...
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Have you considered a HashMap?
Mc. Alvin Bautista
Greenhorn

Joined: Jul 17, 2006
Posts: 10
May I know how to use a hashmap? For example I have a collection of objects then I use a hashmap on that collections? Am I ryt?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Well a HashMap is a Collection that maps keys to values. You could create a class definition or use an array or some other object that contains your range as a key.

You can get details on the HashMap in the API docs.
[ July 17, 2006: Message edited by: Keith Lynn ]
Mc. Alvin Bautista
Greenhorn

Joined: Jul 17, 2006
Posts: 10
What if I have this kind of codes?

Collection number = new Arraylist();
Collection ranges = new ArrayList();

number.add(new Number(0,100));
number.add(new Number(101,200));// I want to get this specific collection
ranges.add(number);


How could I get the specific Collection on the Collection ranges? Do you have any idea with this?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Well, unless you have your own definition of the Number class, you won't be able to do that.

java.lang.Number does not have a constructor that accepts two ints.

Is the idea that you basically are going to have several different ranges of numbers, and want to know which range contains a number you are looking for?
Mc. Alvin Bautista
Greenhorn

Joined: Jul 17, 2006
Posts: 10
By the way, the Number class here is created on my own. I declared this as Number(int begin, int end). Let's say that the begin variable here is a key for a specific record. It means that it is a range of records from a given "begin key" to the given "end key". That's why I made a collection on this records. What I am trying to do is I want to get the specific range of records on the collection of ranges of records. I realy don't have much idea on how to implement these. Can you please help me on this?

By the way thanks for the responses.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
When you are searching for the range, are you going to search for the entire range, or are you going to have an integer and search for the rangs that contains that integer?
Ramen Chatterjee
Ranch Hand

Joined: Apr 27, 2006
Posts: 62
Hi

Ive been following this thread. It would certainly help (me at least) if you could describe the problem in terms of the 'real world'. That is, you are trying to solve a problem (the why) and have mentioned one (potential) way of solving that problem (the how). If you could describe 'the why' a bit more, it may help answer your problem.

Regards

Ramen


Could try harder
Mc. Alvin Bautista
Greenhorn

Joined: Jul 17, 2006
Posts: 10
I got it now. Thanks 4 the idea of Keith. I use the HashMap object to get the Collection of Collections. I got the specific Collections through the use of the key mapped in that Collection. Thanks to you guys....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collection of Collections