0% found this document useful (0 votes)
74 views

Diff Betwen Hashset and Linkdhashset

TreeSet, HashSet, and LinkedHashSet are all implementations of the Set interface that do not allow duplicate elements. TreeSet stores elements in ascending order in a red-black tree, making operations like add, remove and contains slower. HashSet stores elements in a hash table, making operations faster but with no order. LinkedHashSet also uses a hash table but maintains a doubly-linked list, allowing it to iterate over elements in the order they were inserted.

Uploaded by

Srinivas Boini
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Diff Betwen Hashset and Linkdhashset

TreeSet, HashSet, and LinkedHashSet are all implementations of the Set interface that do not allow duplicate elements. TreeSet stores elements in ascending order in a red-black tree, making operations like add, remove and contains slower. HashSet stores elements in a hash table, making operations faster but with no order. LinkedHashSet also uses a hash table but maintains a doubly-linked list, allowing it to iterate over elements in the order they were inserted.

Uploaded by

Srinivas Boini
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Posted by vidya on January 22, 2009

TreeSet HashSet LinkedHashSet


public class public class
HashSet LinkedHashSet
public class TreeSet
extends AbstractSet extends HashSet
extends AbstractSet
implements Set, implements Set,
implements SortedSet, Cloneable, Serializable
Cloneable, Cloneable,
Serializable Serializable
unique values unique values Unique values
is implemented as a
It stores its elements hash table with a
It stores its elements in a red-black tree
in a hash table linked list running
through it
Order : ascending order undefined insertion order
has fast adding to
the start of the list,
better than
Performance : Slow LinkedHashSet and fast deletion
from the interior via
iteration
operations (add, operations (add,
operations (add, remove and contains) remove, contains contains and
and size) remove)

add,
addAll,ceiling,clear,clone,comparator,contains, add, clear, add, clear,
clone, contains, clone, contains,
descendingIterator,descendingSet,first,floor, isEmpty, isEmpty,
hashSet,higher,isEmpty,iterator,last,lower,pollFirst iterator, iterator,
, remove, size remove, size
remove,size,subSet,tailSet
equals, equals,
From AbstractSet: hashCode, hashCode,
equals, hashCode, removeAll removeAll removeAll

AbstractCollection: addAll,
addAll, containsAll,
containsAll, retainAll, toArray, toArray, containsAll, retainAll,
toString retainAll, toArray,
toArray, toArray,
toArray, toString
toString

Set: addAll, add, addAll,


containsAll, equals, hashCode, removeAll, containsAll, clear, contains,
retainAll, toArray, toArray equals, containsAll,
equals,
hashCode,
hashCode, isEmpty,
removeAll, iterator,
retainAll, remove,
toArray, toArray removeAll,
retainAll, size,
toArray, toArray

Posted by vidya on January 22, 2009

HashMap HashTable TreeMap LinkedHashMap


public class
public class public class TreeMap<K,V>
HashMap<K,V> Hashtable<K,V> extends
extends extends
AbstractMap<K,V> Dictionary<K,V> AbstractMap<K,V> public class
LinkedHashMap<K,V>
implements implements implements extends HashMap<K,V>
Map<K,V>, Map<K,V>, 
 NavigableMap<K,V>, implements Map<K,V>
 Cloneable, Cloneable,
Cloneable, 
 Serializable  Serializable
Serializable

Unidentified Order Decending Order Ascending Order Insertion Order


UnSynchronized Synchronized UnSynchronized UnSynchronized
The values can be null.
does not let you have The values can be null. But The values can be null. But
But the key should be
null value for key. the key should be unique the key shoul
unique

« TreeSet vs HashSet vs LinkedHashSet


HashMap Vs HashTable Vs TreeMap Vs LinkedHashMap »

ArrayList vs LinkedList vs Vector


Posted by vidya on January 22, 2009

ArrayList LinkedList Vector


public class
public class
Vector<E>
ArrayList<E> public class
extends 
extends LinkedList<E>
AbstractList<E> extends
AbstractList<E>
implements AbstractSequentialList<E>
implements
List<E>,
List<E>,
implements List<E>,
 RandomAccess,
RandomAccess
 Deque<E>, Cloneable,
Cloneable,
Serializable
,Cloneable,
Serializable
Serializable

implemented as a Growable array of


Resizeable doubly-linked chain of objecs,unordered,
Array,unordered, nodes,unordered, allows allows duplicates and
allows duplicates and duplicates accepts null values.It
accepts null values can grow or shrink as
and accepts null values needed
not synchronized  synchronized and
Not synchronized
hence not thread-safe. thread-safe.
Provides Random Provides optimal sequential Provides Random
Access access. Access
Use: Inserts at the beginning or
use Vector class when
Use ArrayList if there
there are multiple
is single Thread end are very fast.Deletions
threads in the system
from the middle are very fast
http://www.interviewmantra.net/2008/12/c-interview-questions-with-solutions-4.html#ques1

http://www.interviewmantra.net/2009/10/10-star-pattern-programs.html

You might also like