Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Effieient collection implementation for faster search.

 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have to use a collection store a pretty large number of objects . Which is a better collection to use in case I have to constantly perform search operations on the collection? I don't actually need a map so that rules out the ones that are based on hashing functions.

Cheers,
Raj.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
constantly perform search operations on the collection?


Searching based on what? What is the nature of these objects?

I don't actually need a map


How did you come to that conclusion?

Bill
 
Campbell Ritchie
Sheriff
Posts: 48424
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends which order you need to keep the contents of the Collection in. You need to compare the List Set SortedSet and Map interfaces to see how they store their contents.

Most List contains methods probably run in linear time, hash methods probably constant time unless the load factor is high, and sorted set methods probably in logarithmic time.

Performance is unpredictable; you will have to try it and see what happens; and good luck with it
[ November 30, 2008: Message edited by: Campbell Ritchie ]
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Kamal:
I have to use a collection store a pretty large number of objects

How large do you consider large? HashMaps are O(1) its really hard to beat that, but they do have a fairly large constant.

Before we can help, you need to be more specific. And make sure that this is not premature optimization.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic