Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help choosing Collection?

 
Bashar Ayyash
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a servlet question, moving to Java in General (beginner).

Dave
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amy Medrat
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic