File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collection- Fast Retrieval

 
aakash bhatt
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Greg Reinl
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to take a look at the Collections Trail of Sun's Java Tutorial.
Moving this to the Performance forum...
 
John Smith
Ranch Hand
Posts: 2937
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vector and hashtable are fast.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic