This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft 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 Java 8 in Action this week in the Java 8 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: 12682
    
    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: 36575
    
  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: 4639
    
    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 would you design this java class
Session Size
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 ?