Java – Set Interface

Java Set Interface methods, variables available in Java 8 release are listed below. We will publish example program on each methods ASAP.

Methods in Java Set Interface

S.No Method & Description
1 boolean add(E e)

Adds the specified element to this set if it is not already present (optional operation).
2 boolean addAll(Collection<? extends E> c)

Adds all of the elements in the specified collection to this set if they’re not already present (optional operation).
3 void clear()

Removes all of the elements from this set (optional operation).
4 boolean contains(Object o)

Returns true if this set contains the specified element.
5 boolean containsAll(Collection<?> c)

Returns true if this set contains all of the elements of the specified collection.
6 boolean equals(Object o)

Compares the specified object with this set for equality.
7 int hashCode()

Returns the hash code value for this set.
8 boolean isEmpty()

Returns true if this set contains no elements.
9 Iterator<E> iterator()

Returns an iterator over the elements in this set.
10 boolean remove(Object o)

Removes the specified element from this set if it is present (optional operation).
11 boolean removeAll(Collection<?> c)

Removes from this set all of its elements that are contained in the specified collection (optional operation).
12 boolean retainAll(Collection<?> c)

Retains only the elements in this set that are contained in the specified collection (optional operation).
13 int size()

Returns the number of elements in this set (its cardinality).
14 default Spliterator<E> spliterator()

Creates a Spliterator over the elements in this set.
15 Object[] toArray()

Returns an array containing all of the elements in this set.
16 <T> T[] toArray(T[] a)

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. Java – Dictionary Class
  2. Java – ConcurrentHashMap Class
  3. Java ArrayList isEmpty() method with example
  4. Java – ToIntBiFunction Interface
  5. Java – ForkJoinPool Class
  6. Java – StringJoiner Class
  7. Java – ConcurrentLinkedQueue Class
  8. Java – Optional Class
  9. Java – ListResourceBundle Class
  10. Java – ArrayDeque Class
  11. Java – RunnableFuture Interface
  12. Java – RandomAccess Interface
  13. Java ArrayList remove(Object o) method with example
  14. Java – Comparator Interface
  15. Java – AbstractSet Class

Be the first to comment

Leave a Reply