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

Help choosing Collection?

Bashar Ayyash
Ranch Hand

Joined: Jun 24, 2004
Posts: 44
Hi Guys,

As JAVA leaders I need your advice on choosing the best Collection (HashTable, HashMap,,,etc.) that is uitable for me. I need it to enables me sotre and access: 1) Object 2) Two boolean values 3) An index
Like follow:

index Object boolean1 boolean2
----- ------ -------- --------

Best Regards,
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This is not a servlet question, moving to Java in General (beginner).

Dave
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
I am not sure if you have that facility in Collectio classes. But why can not you store boolean1 & boolean2 values in the same object.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

1) Object 2) Two boolean values 3) An index

You could store this information in a bean, and use a collection to store the beans. Which collection depends on your needs. Maybe an ArrayList.


[My Blog]
All roads lead to JavaRanch
Amy Medrat
Greenhorn

Joined: Mar 05, 2006
Posts: 15
Probably it depends on how you would be accessing the data..

1. If you want to access the data with the help of a key lets say the index value here you can put the index as key and the rest values clubbed in a object as a value object in either HashMap or HashTable.
The difference between HashMap and HashTable is that HashTable is synchronized where as HashMap is not.

2. If you do not think you would be accessing the data by key you can put it in an Arraylist as Satou mentioned above.


medRat
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
That was a good suggestion to put your several data elements into a little class and store objects of that class in your collection. Here is a collection crib sheet I made because I couldn't keep them all in my head. There are more that this but these are the common ones.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by KJ Reddy:
I am not sure if you have that facility in Collectio classes. But why can not you store boolean1 & boolean2 values in the same object.


I am not sure where you are coming from here. You certainly CAN store two boolean variables in the same object:


Then you could store this in some Collection.

Layne


Java API Documentation
The Java Tutorial
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Bashar Ayyash:
Hi Guys,

As JAVA leaders I need your advice on choosing the best Collection (HashTable, HashMap,,,etc.) that is uitable for me. I need it to enables me sotre and access: 1) Object 2) Two boolean values 3) An index
Like follow:

index Object boolean1 boolean2
----- ------ -------- --------

Best Regards,


This only describes WHAT data you need to store. In order to decide which Collection to use, you also need to consider HOW you want to store and access this data. Perhaps it will help if you describe what this data represents. Feel free to use this forum as a sounding board. There are plenty of people here that will pipe in with suggestions.

Layne
Bashar Ayyash
Ranch Hand

Joined: Jun 24, 2004
Posts: 44
Guys I want to say one word, THANK YOU FROM ALL MY HEART, I can't express my thankfull to you. You are giving the true meaning of the net, this is the purpose beyond creating the net to (Share) knowledge.
Also, one of the main things that made me choose Open Source Technology (JAVA) is this.

Thank you again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help choosing Collection?