Set DataStructure

A

Anony!

Hi

I know that a list contains duplicates and a set does not.

Whats the difference between the 3 implementations of the set interface?
They being the hashset, linkedhashset, and treeset?

What I predict:

1. Hashset: dont know.
2. LinkedHashSet: no order, elements in a linkedlist structure, and has no
duplicates.
3. Treeset: orders elements in a tree-like structure and has no duplicates.

Anyone want to complete the picture?

Thanks.
AaA
 
M

Murray

1. Hashset: dont know.

HashSet has no guaranteed order. Order may even change over time. It is
based on the hashCode of an object (which is essentially random) and it is
backed by a HashMap implementation

LinkedHashSet has a predictable order i.e. insertion order

TreeSet uses natural ordering of Comparable elements, or a supplied
Comparator

By the way, all this info is easily found in the Java API e.g.
http://java.sun.com/j2se/1.4.2/docs/api/ or you own local copy
 
A

Anony!

Anony! said:
HashSet has no guaranteed order. Order may even change over time. It is
based on the hashCode of an object (which is essentially random) and it is
backed by a HashMap implementation

I thought a hashcode for an object is unique to that object and would not
change.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top