Which of the core Collection interface represents an implementation that will store unique?
Prior to Java 2, Java provided ad hoc classes such as Dictionary, Vector, Stack, and Properties to store and manipulate groups of objects. Although these classes were quite useful, they lacked a central, unifying theme. Thus, the way that you used Vector was different from the way that you used Properties. Show
The collections framework was designed to meet several goals, such as −
Towards this end, the entire collections framework is designed around a set of standard interfaces. Several standard implementations such as LinkedList, HashSet, and TreeSet, of these interfaces are provided that you may use as-is and you may also implement your own collection, if you choose. A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following −
In addition to collections, the framework defines several map interfaces and classes. Maps store key/value pairs. Although maps are not collections in the proper use of the term, but they are fully integrated with collections. The Collection InterfacesThe collections framework defines several interfaces. This section provides an overview of each interface −
The Collection ClassesJava provides a set of standard collection classes that implement Collection interfaces. Some of the classes provide full implementations that can be used as-is and others are abstract class, providing skeletal implementations that are used as starting points for creating concrete collections. The standard collection classes are summarized in the following table −
The AbstractCollection, AbstractSet, AbstractList, AbstractSequentialList and AbstractMap classes provide skeletal implementations of the core collection interfaces, to minimize the effort required to implement them. The following legacy classes defined by java.util have been discussed in the previous chapter −
The Collection AlgorithmsThe collections framework defines several algorithms that can be applied to collections and maps. These algorithms are defined as static methods within the Collections class. Several of the methods can throw a ClassCastException, which occurs when an attempt is made to compare incompatible types, or an UnsupportedOperationException, which occurs when an attempt is made to modify an unmodifiable collection. Collections define three static variables: EMPTY_SET, EMPTY_LIST, and EMPTY_MAP. All are immutable.
How to Use an Iterator ?Often, you will want to cycle through the elements in a collection. For example, you might want to display each element. The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface. Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list and the modification of elements.
How to Use a Comparator ?Both TreeSet and TreeMap store elements in a sorted order. However, it is the comparator that defines precisely what sorted order means. This interface lets us sort a given collection any number of different ways. Also this interface can be used to sort any instances of any class (even classes we cannot modify).
SummaryThe Java collections framework gives the programmer access to prepackaged data structures as well as to algorithms for manipulating them. A collection is an object that can hold references to other objects. The collection interfaces declare the operations that can be performed on each type of collection. The classes and interfaces of the collections framework are in package java.util. Which of the core collection interface represents an implementation that will store unique values?LinkedHashSet. LinkedHashSet class represents the LinkedList implementation of Set Interface. It extends the HashSet class and implements Set interface. Like HashSet, It also contains unique elements.
Which of the core collection interface represents an implementation?The AbstractCollection, AbstractSet, AbstractList, AbstractSequentialList and AbstractMap classes provide skeletal implementations of the core collection interfaces, to minimize the effort required to implement them. Sr.No. This implements a dynamic array. It is similar to ArrayList, but with some differences.
Which collection interface is responsible for maintaining unique?Which of this interface must contain a unique element? Explanation: Set interface extends collection interface to handle sets, which must contain unique elements.
Which of the following options is a collection interface that will provide the class implementation for various collections?Collection Interfaces
These common interfaces define the basic functionality for each collection class. The key collections interfaces are – IEnumerable, ICollection, IDictionary and IList. IEnumerable acts as a base interface for all the collection types that is extended by ICollection.
|