The AbstractSet class extends the class AbstractCollection and implements the interface Set. This class implements the Set interface alike the AbstractClass implements the Collection interface except all of the constructors and methods of its subclasses must follow the extra constraints enforced by the Set interface.
Java Collection Framework - AbstractSet
The AbstractSet class extends the class AbstractCollection and implements the interface Set. This class implements the Set interface alike the AbstractClass implements the Collection interface except all of the constructors and methods of its subclasses must follow the extra constraints enforced by the Set interface. Except the equals and hashCode implementations of AbstractCollection the AbstractSet class does not override any of the implementation of AbstractCollection. AbstractSet class is a part of java.util package.
Syntax
public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E>
Constructor of AbstractSet
AbstractSet() : This only constructor of this class which is invoked typically implicitly by the subclass constructor.
Methods of AbstractSet
This class provides the following methods :
- equals()
- hashCode()
- removeAll()
syntax : public boolean equals(Object o)
syntax : public int hashCode()
syntax : public boolean removeAll(Collection<?> c)
Example
package devmanuals.com; import java.util.AbstractCollection; import java.util.List; import java.util.ArrayList; import java.util.Iterator; class AbsCollection extends AbstractCollection<Object> { List<Object> list = new ArrayList<Object>(); public boolean add(Object e) { list.add(e); System.out.println(list); return true; } public Iterator iterator() { Iterator<Object> it = list.iterator(); while (it.hasNext()) System.out.println(it.next()); return null; } public int size() { System.out.println(list.size()); return 0; } } public class AbstractCollectionDemo { public static void main(String[] args) { AbsCollection abd = new AbsCollection(); System.out.println("Elements of list = "); for (int i = 0; i <= 4; i++) { abd.add(i); } System.out.println("Display of elements using Iterator "); abd.iterator(); System.out.println("Size of list = " ); abd.size(); } }
Output :
Elements of Set= 0 1 2 3 4 Display the elements of set using iterator = 0 1 2 3 4 Size of set = 5 Is set empty : false |
[ 0 ] Comments