It returns true if the elements are added otherwise returns false. addAll(): This method adds a collection of elements to the collection. If the element is added to the collection, it will return true otherwise false, if the element is already present and the collection doesn’t allow duplicates.Ģ. The general syntax for add() method is as follow: add(Object element) : boolean add(): This method is used to add or insert an element in the collection. The Collection interface consists of a total of fifteen methods for manipulating elements in the collection. It extends the Map interface which in turn is implemented by TreeMap classes. This interface represents a Map whose elements are stored in their natural ordering. HashMap, HashTable, LinkedHashMap, TreeMap classes implements Map interface. It doesn’t allow to store the duplicate keys but duplicate values are allowed.ģ. Map uses a hashing technique for storing key-value pairs. The hierarchy of the map interface is shown in the below figure.Ģ. It represents an object that stores and retrieves elements in the form of a Key/Value pairs and their location within the Map are determined by a Key. Map interface is not inherited by the collection interface. LinkedList and ArrayDeque classes implement the Deque interface.ġ. i.e, it supports insertion and removal at both ends of an object of a class that implements it.ĥ. It is a linear collection of elements in which elements can be inserted and removed from either end. The hierarchy of the deque interface is shown in the below figure.Ĥ. Deque interface extends the queue interface and uses its method to implement deque. This interface was added to the collection framework in Java SE 6.ģ. A deque (double-ended queue) is a sub-interface of queue interface. LinkedList, Priority queue, ArrayQueue, Priority Blocking Queue, and Linked Blocking Queue are the concrete subclasses that implement the queue interface.ġ. This interface represents a special type of list whose elements are removed only from the head.ģ. Just like a queue in a supermarket or any shop.Ģ. A queue is an ordered of the homogeneous group of elements in which new elements are added at one end(rear) and elements are removed from the other end(front). TreeSet implements the sorted interface.ġ. This interface extends a set whose iterator transverse its elements according to their natural ordering.Ģ. It can be iterated by using Iterator but cannot be iterated using ListIterator.ġ. HashSet, LinkedHashSet, TreeSet classes implements the set interface and sorted interface extends a set interface.ĥ. Set does not allow any duplicate elements.Ĥ. All the elements in a set can be in any order.ģ. Set interface does not maintain any order while storing elements and while retrieving, we may not get the same order as we put elements. i.e, It is used to store the collection of unique elements.Ģ. This interface represents a collection of elements that contains unique elements. ArrayList, vector, and LinkedList are three concrete subclasses that implement the list interface.ġ. The list allows storing duplicate elements in Java.Ĥ. We can insert elements into the list at any location. List maintains an order of elements means the order is retained in which we add elements, and the same sequence we will get while retrieving elements.ģ. This interface represents a collection of elements whose elements are arranged sequentially ordered.Ģ. A map is not inherited by Collection interface.ġ. List, Queue, and Set have three components which extends the Collection interface. Using this iterator object, we can iterate over the elements of the collection.ģ. The function of the iterator method is to return the iterator object. The iterable interface has only one method called iterator(). Collection interface extends the Iterable interface.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |