aspose file tools*
The moose likes Performance and the fly likes Collection- Fast Retrieval Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Collection- Fast Retrieval" Watch "Collection- Fast Retrieval" New topic
Author

Collection- Fast Retrieval

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
In my application i have to use Collections but can suggest when to use for what scenario?
Fast Retrival of data from a huge collection is the biggest criteria so which collection Class shall I use
Regards,
aakash
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Here's my Collections Crib Sheet that I use to figure out which collection to use. A collection is just a place to put a bunch of things, maybe all the same class, maybe not. Any time you could have one or more of something, a collection may be just the ticket. Say you wanted to keep track of all the courses you have taken and calculate a GPA. You could load a bunch of Course objects from a file or database and add them to a collection, then go through the collection and get the grades. Hope that helped. Holler for more if not!


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
Greg Reinl
Ranch Hand

Joined: Feb 11, 2003
Posts: 45
Thanks for sharing your "Crib Sheet". What type of collection to use where is an ongoing question for me and this will help sort things out.
I do have a follow on question: Should I avoid using Hashtables and Vectors? If so, why? Is it a performance or maintainability issue?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Hashtables are no problem, I use them all the time.
They are a little bit slower than HashMaps but old habits die hard
Vectors ARE slow. Using an ArrayList instead can give you retrieval and storage times that can be 10x faster or more as compared to Vectors (I've tested this, a Servlet needed 200ms to run when using Vectors (it used Vectors for internal storage of data retrieved from a database, think 5 or so Vectors of maybe a hundred entries each), simply replacing those with ArrayLists dropped that to under 20ms. Those 20ms were mostly database access times).


42
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You might want to take a look at the Collections Trail of Sun's Java Tutorial.
Moving this to the Performance forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Hashtables and Vectors are the legacy collections and should not be used, -- if you do, you may be stuck with the old/inefficient implementation forever. HashMaps and ArrayLists, on the other hand, would allow your code to become better along with the evolution of Java, and to use all the benefits of code reuse and mutation.
Ouaknin lionel
Greenhorn

Joined: Sep 12, 2003
Posts: 14
Vector and hashtable are fast.


"Nobody will ever need more than 256 kb of ram" -Bill Gates
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collection- Fast Retrieval