java.util.HashSet
is implemented with a hash table. Access time is O(1). Entries are unsorted.java.util.TreeSet
is implemented as a balanced binary tree. Access time is O(log N). Entries are sorted.
A set is an unordered collection of elements that has no duplicate members. elements retrieved by identity, not index.
Set Interface
Set Implementations
We have following as implementing classes:
public interface Set {
// Basic Operations
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(Object element); // Optional
boolean remove(Object element); // Optional
Iterator iterator();
// Bulk Operations
boolean containsAll(Collection c);
boolean addAll(Collection c); // Optional
boolean removeAll(Collection c); // Optional
boolean retainAll(Collection c); // Optional
void clear(); // Optional
// Array Operations
Object[] toArray();
Object[] toArray(Object a[]);
}
No comments:
Post a Comment