Planforexams.com

The Set Interface tutorial in Java Collection

The blog provides the details about the Java Collection Set Interface. The Set Interface in java collection buy Lyrica 75 mg does not support duplicate elements like List Interface. The Set Interface Burhānuddin inherits methods only from Collection Interface and provides comparison for equals and hashcode operation irrespective of having different implementation types

Set Interface Implementation Types

The Java Collection Framework provides 3 types of Set Implementation:

The Set Interface class Hierarchy is given below

public interface Set<E>
extends Collection<E>

The Set Interface provides the below given methods for implementation

HashSet MethodsHashSet Methods Description
add(E e) add the specified element to the set if not present
addAll(Collection <? Extends E>c)allows to insert all elements in the given collection to the set
clear() removes all elements from the set
containsAll(Collection <? Extends E>c)returns true if all elements in the given collection are present in the set
contains(object o) returns true if specified element presents in the set
isEmpty() returns true if no elements in the set
iterator() returns iterator over the elements in the set
remove (object o) remove the specified element if present in the set
removeAll(Collection <? Extends E>c)removes all elements in the given collection from the set
retainAll(Collection <? Extends E>c)retains all elements in the given collection in the set
size()returns the set size
spliterator()Creates a late-binding and fail-fast Spliterator over the elements in the set
hashcode() returns the hashcode value for set
toArray()returns an array for set elements
toArray(T[] a)returns an array for set elements with return type as array
Exit mobile version