Java Collections Framework:
The basic structure of the framework is defined by a number of interfaces, as shown in Figure. The most important of these are the Collection and the Map interfaces. The distinction is clear if we look at the method offered by each interface for adding an item to the relevant collection class.
The Collection interface specifies the method:
boolean add(E el);
where E is the type the interface is implemented for. This can be used by most of the 'classic' data structures, such as arrays, lists, stacks or sets, and the framework offers implementations for some of these.
The Map interface specifies the insertion method:
V put(K key, V value);
where K and V are the key and value types. Classes that implement Map deal with key-value pairs in the same way as we saw with hash tables earlier. Values are retrieved from a map by supplying the key to the get method, which is defined as follows:
V get(Object key);
Although interfaces are not classes, as we have seen, it is possible for an interface to inherit from another interface. The Java 2 Collections Framework defines a hierarchy of interfaces, most of which are shown in Figure.
This shows that there are interfaces to define the operations for lists, sets and maps, and more specialized interfaces for sorted sets and sorted maps, which as the name suggests can return their data in some appropriate ordering. The Iterator interface and its more specialized subinterface ListIterator are powerful tools for traversing the various collections in a consistent way, without the need to know the implementation details of each collection.
The implementation of the interfaces is handled by another hierarchy - this time the hierarchy of collection classes, shown in Figure.
Figure shows six concrete classes that inherit from the five abstract classes, which are shown shaded. This shows that the abstract concept of a set, for example, as defined by interface Set and partially implemented by abstract class AbstractSet, can be finally implemented in one of two ways - a HashSet (using a hash table as the underlying data structure) or a TreeSet (using a tree as the underlying data structure). Similarly there are two possible implementations for lists (using an array approach or a linked list) and two ways of implementing maps (with hash table or tree options, similar to sets). A tree is a sort of data structure widely used in computer science. For this course, all you need to know is that trees are particularly useful for efficient storage and retrieval of data in a particular sorted order.
The framework makes it possible for you (or the language designers or some third party) to add other implementations, if none of the standard implementations suits your requirements. As long as you stay within the framework specified by the interfaces and the abstract classes, any new implementation should require little or no change to code that previously used another implementation.
So much for how the framework is organized. There is much more to learn about the careful design of the Java 2 Collections Framework, but we now move on to look at some examples of how it is used. This should be much more straightforward.
Java Assignment Help - Java Homework Help
Struggling with java programming language? Are you not finding solution for your Java Collections Framework homework and assignments? Live Java Collections Framework experts are working for students by solving their doubts & questions during their course studies and training program. We at Expertsmind.com offer Java Collections Framework homework help, java assignment help and Java Collections Framework projects help anytime from anywhere for 24x7 hours. Computer science programming assignments help making life easy for students.
Why Expertsmind for assignment help
- Higher degree holder and experienced experts network
- Punctuality and responsibility of work
- Quality solution with 100% plagiarism free answers
- Time on Delivery
- Privacy of information and details
- Excellence in solving java programming language queries in excels and word format.
- Best tutoring assistance 24x7 hours