0% found this document useful (0 votes)
9 views2 pages

Set (I)

Mech

Uploaded by

vasalahruthik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Set (I)

Mech

Uploaded by

vasalahruthik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Set(I)

1. It is a predefined interface present in the util package.


2. This interface follows the Map interface to perform
operations.
3. It will allow null values but it doesn't allow duplicate
elements.
4. It will follow the hashing mechanism but it doesn't follow
any order of elements (Random Access)
For this interface, we have three implementation classes
● HashSet
● LinkedHashSet
● TreeSet

HashSet:
● It is a predefined class present in util package.
● It will inherit the properties from the Set interface.
● It allows only unique elements and Null values.
● It follows the HashMap class to perform operations.
● Here there is no order of elements because it follows a
hashing mechanism, to be exact, it will follow a hashcode
algorithm to insert and get the values.
Constructors:
● HashSet()
● HashSet(collection)
Methods:
● public boolean isEmpty()
● public int size()
● public boolean add(Object)
● public void addAll(Collection)
● public boolean contains(Object)
● public boolean containsAll(Collection)
● public void remove(Object)
● public void removeAll(Object)
● public void clear()
● public Iterator iterator()
● public Object[] toArray()
● public int hashcode()

LinkedHashSet:
● It is a predefined class present in the util package.
● It follows a doubly linked list for adding elements.
● It does not allow duplicate values and it allows null elements.
● Here it follows the insertion order.
Constructors:
● LinkedHashSet()
● LinkedHashSet(Object)
Methods: (same as HashSet)
● public boolean isEmpty()
● public int size()
● public boolean add(Object)
● public void addAll(Collection)
● public boolean contains(Object)
● public boolean containsAll(Collection)
● public void remove(Object)
● public void removeAll(Object)
● public void clear()
● public Iterator iterator()
● public Object[] toArray()
● public int hashcode()

You might also like