aspose file tools*
The moose likes Java in General and the fly likes Effieient collection implementation for faster search. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Effieient collection implementation for faster search." Watch "Effieient collection implementation for faster search." New topic
Author

Effieient collection implementation for faster search.

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

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

Joined: Mar 22, 2000
Posts: 12806
    
    5
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

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

Joined: Aug 11, 2007
Posts: 4659
    
    5

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Effieient collection implementation for faster search.