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
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers
- Java – Dictionary Class
- Java – ConcurrentHashMap Class
- Java ArrayList isEmpty() method with example
- Java – ToIntBiFunction Interface
- Java – ForkJoinPool Class
- Java – StringJoiner Class
- Java – ConcurrentLinkedQueue Class
- Java – Optional Class
- Java – ListResourceBundle Class
- Java – ArrayDeque Class
- Java – RunnableFuture Interface
- Java – RandomAccess Interface
- Java ArrayList remove(Object o) method with example
- Java – Comparator Interface
- Java – AbstractSet Class
Leave a Reply
You must be logged in to post a comment.