This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 12678
    
    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


Java Resources at www.wbrogden.com
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36482
    
  16
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: 4637
    
    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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Effieient collection implementation for faster search.
 
Similar Threads
how to set up a navigation tree in struts?
html-el:select embeded in js, what should I do to let it runing or not Unterminated String Constant
Which Java Collection construct will be suitable ?
How would you design this java class
Session Size