We use cookies to ensure you have the best browsing experience on our website. Otherwise, returns false. e==null : o.equals(e)) ." This interface extends the queue interface. Since all the subclasses implement the list, we can instantiate a list object with any of these classes. The Collection interface is not directly implemented by any class. Please write to us at [email protected] to report any issue with the above content. 1. boolean add (Object obj) Adds obj to the invoking collection. The Collection interface is not directly implemented by any class. If a collection implementation doesn’t implement a particular operation, it should define the corresponding method to throw UnsupportedOperationException. This set interface is implemented by various classes like HashSet, TreeSet, LinkedHashSet, etc. The array elements are copies of the collection elements. For example. This collection is used when we wish to avoid the duplication of the objects and wish to store only the unique objects. Returns an array containing only those collection elements whose type matches that of array. Returns an iterator over the elements in this collection. There are various classes like PriorityQueue, Deque, ArrayDeque, etc. Compares the specified object with this collection for equality. These include the following: List: This is a child interface of the collection interface. boolean add ( E obj ) Used to add objects to a collection. How to remove an element from ArrayList in Java? Otherwise, returns false. However, it is implemented indirectly via its subtypes or subinterfaces like List, Queue, and Set. The class which implements this interface is TreeSet. List Interface. It is one of the root interfaces of the Collection Hierarchy. For example, whenever we try to book a ticket, the tickets are sold at the first come first serve basis. To iterate over the elements of Collection we can use iterator() method. Removes all elements from the invoking collection except those in c. Returns true if the collection changed (i.e., elements were removed). Returns an array containing all of the elements in this Collection. For example, the ArrayList class implements the List interface which is a subinterface of the Collection Interface. Removes all the elements of this collection that satisfy the given predicate. boolean addAll ( Collection C ) Add all elements of collection C to the invoking collection. Ensures that this collection contains the specified element (optional operation). Attention reader! Returns false if obj is already a member of the collection, or if the collection does not allow duplicates. Returns true if the invoking collection is empty. It implements the Iterable interface. This interface is dedicated to the data of the list type in which we can store all the ordered collection of the objects. Removes all the elements from this collection (optional operation). Write Interview The Collection interface is the foundation upon which the collections framework is built. The Collection interface is implemented by AbstractCollection, AbstractList, AbstractQueue, AbstractSequentialList, AbstractSet, ArrayBlockingQueue, ArrayDeque, ArrayList, AttributeList, BeanContextServicesSupport, BeanContextSupport, ConcurrentHashMap.KeySetView, ConcurrentLinkedDeque, ConcurrentLinkedQueue, ConcurrentSkipListSet, CopyOnWriteArrayList, CopyOnWriteArraySet, DelayQueue, EnumSet, HashSet, JobStateReasons, LinkedBlockingDeque, LinkedBlockingQueue, LinkedHashSet, LinkedList, LinkedTransferQueue, PriorityBlockingQueue, PriorityQueue, RoleList, RoleUnresolvedList, Stack, SynchronousQueue, TreeSet, Vector. Returns true if the invoking collection and obj are equal. How to determine length or size of an Array in Java? This interface is dedicated to storing all the elements where the order of the elements matter. Returns false if obj is already a member of the collection, or if the collection does not allow duplicates. The List interface is found in the java.util package and inherits the Collection interface. Returns true if this collection contains all the elements in the specified collection. Note: In the above syntax, we can replace any class with ArrayList if that class implements the Collection interface. Removes all elements from the invoking collection. The Collection interface is a member of the Java Collections Framework. Returns true if this collection contains no elements. Returns an array containing all the elements in this collection, using the provided generator function to allocate the returned array. See your article appearing on the GeeksforGeeks main page and help other Geeks.