Friday, October 30, 2009

Performance : List and Set

In List interface implementations, before adding the data and to avoid duplication, we need to make a check whether already the data exist in the list. List implementation will nicely work <5000 entry, we do not see much of performance different, not more than milliseconds different.

Once we started adding more entries and started doing manipulations, we will be in position to ask questions and answer ourself, what went wrong, what could be the alternate. Cool..., Here you go.

Now, we think of Set interface and implementations. All the Set implementations avoids duplicate entries and also reports back to caller with boolean value - true, if this set did not already contain the specified element.

These Set interface implementation gives best performance in huge data and comes with different flavours

HashSet
No guarantee for order in which added,and no guarantee for order based on the value.
LinkedHashSet
Guaranteed order in which added.
TreeSet
SortedSet Implementation - Guaranteed Ascending order on value.

HashSet = [9, 25, 4, 36, 100, 1, 49, 81, 16, 64]
LinkedHashSet = [100, 81, 64, 49, 36, 25, 16, 9, 4, 1]
TreeSet = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Performance wise HashSet gives best ,and LinkedHashSet in second position, and TreeSet.

However, Based on the need/usage, any of these Set implementation has to be used :)

Please refer for more details - http://java.sun.com/developer/JDCTechTips/2002/tt1105.html

Reactions:

0 comments:

Post a Comment

Recent Posts

Unix Commands | List all My Posts

Texts

This blog intended to share the knowledge and contribute to JAVA Community such a way that by providing samples and pointing right documents/webpages. We try to give our knowledege level best and no guarantee can be claimed on truth. Copyright and Terms of Policy refer blogspot.com

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More