Javase Introductory Learning 33:java Collection Framework Overview

Source: Internet
Author: User
Tags new set

A collection of frames (1) concept of a set

A collection of real life: a lot of things come together.

A collection in mathematics: The totality of things that have a common attribute.

collection Classes in Java: A tool class, like a container, that stores any number of objects with common attributes.

(2) concept of Set frame

With the concept of a collection, what is a collection framework? A collection framework is a uniform standard architecture that is defined for representing and manipulating collections. Any

The collection framework contains three chunks of content: external interfaces, interface implementations, and algorithms for set operations.

1 Interface: the abstract data type that represents the collection. The interface provides the possibility for us to perform separate operations on the content represented in the collection. interface allows

The collection independently manipulates the details of its representation. In object-oriented languages, interfaces usually form a hierarchy.

2 Implementation (Class): that is, the concrete implementation of the interface in the collection framework. Actually, they are the reusable data structures.

3 algorithm: An object that implements an interface in a set framework to perform a useful calculation, such as find, sort, etc. These

Algorithms are often polymorphic, because the same method can behave differently when the same interface is implemented by multiple classes. In fact, the algorithm is a reusable letter

Number. If you have learned C + +, you should be familiar with the Standard Template Library (STL) in C + +, which is a perfect example of a well-known set of frameworks.

The collection framework is designed to meet several goals:

1 The framework must be high-performance. The implementation of the basic set (dynamic array, linked list, tree, hash table) must also be efficient.

2 The framework allows different types of collections to work in a similar way, with a high degree of interoperability.

3 the expansion and adaptation of a set must be simple.

(3) concept of the Java Collection Framework

In the Java language, designers have made some specifications (interfaces) and implementations of commonly used data structures and algorithms (classes that implement interfaces specifically). In addition to the collection,

The Java Collection Framework also defines several map interfaces and classes. A key/value pair is stored in the map. Although map is not collections, they are fully integrated in

The collection. All abstract data structures and operations (algorithms) are collectively referred to as the Java Collection Framework (Java Collection Framework).

Java programmers do not have to take into account data structures and algorithm implementation details when they are applied, just create some objects with these classes and then directly

You can use it, which greatly improves the efficiency of programming.

To do this, the entire collection framework is designed around a standard set of interfaces. You can use the standard implementations of these interfaces directly, such as: LinkedList,

HashSet and HashMap, you can also implement your own collection via these interfaces.

(4) The role of the Java Collection Framework

1 in the interior of the class, the data is organized.

2 Simple and fast search for large number of entries.

3 has a collection interface that provides a series of ordered elements, and can quickly insert or delete elements in the middle of a sequence.

4 has a set of interfaces, provides a mapping relationship, you can use the keyword (key) to quickly find the corresponding unique object, and this keyword can be any

The type of meaning.

(5) Why collections are chosen instead of arrays--vs. arrays

1 The length of the array is fixed and the set length is variable.

2 arrays can only access elements by subscript, types are fixed, and some collections may find specific objects that are mapped by any type.

Two Java Collection Framework Architecture

Java provides a rich collection framework that contains a number of interfaces, abstract classes, and implementation classes . These interfaces and classes provide a wealth of

capabilities to meet basic aggregation needs. is the whole body structure of this frame :


The Java Collection Framework diagram explains:

1 set Interface: 6 interfaces (short dashed lines), representing different collection types, is the basis of the collection framework.

2 Abstract class: 5 abstract classes (long dashed lines), partial implementations of the collection interface. Can be extended to custom collection classes.

3 Implementation Class: 8 implementation Class (solid line representation), the specific implementation of the interface.

Our main learning interface and implementation class, that is, simplifying the future Java Collection Framework diagram:


We mainly study three types of interfaces:

1.Collection is an interface that contains the basic operations and properties of a collection. The collection contains the list and set of the two major branches.

(1) List is an ordered queue, each element has its index, the index value of the first element is 0,list implementation class has ArrayList,

Linkedlist,vector and Stack.

(2) Set is a set that is not allowed to have duplicate elements. The implementation class for set has HashSet and TreeSet. HashSet relies on HashMap, which actually

is implemented through HashMap, and TreeSet relies on treemap, which is actually implemented through TREEMAP.

2. Map is a mapped interface, which is a Key-value key-value pair. Each element in the map contains the value corresponding to a key and key.

(1) Abstractmap is an abstract class that implements most of the APIs in the map interface, and Hashmap,treemap,weakhashmap is

Inheritance and Abstractmap.

(2) Although Hashtable inherits from dictionary, it implements the map interface.

3. Iterator is a tool that iterates through a collection, and we typically use a iterator iterator to iterate through the collection. Collection relies on iterator because

The collection implementation class implements the iterator () method, returning a iterator object. Listiterator is specifically designed to traverse the list.

Three integrated frame (1) Assembly interface

The collection framework defines some interfaces, and the following table provides an overview of each interface:


(2) Collection class

Java provides a set of standard collection classes that implement the collection interface. Some of these are specific classes that can be used directly, while another

Some are abstract classes that provide a partial implementation of the interface. The standard collection classes are summarized in the following table:



(3) Set algorithm

The collection framework defines several algorithms that can be used for collections and mappings. These algorithms are defined as static methods of the collection class. When trying to compare incompatible types

, some methods can throw classcastexception exceptions. When attempting to modify a non-modifiable collection, throw

Unsupportedoperationexception exception.

A collection defines three static variables: Empty_set empty_list,empty_map. None of these variables can be changed.

(4) iterators

Typically, you would want to iterate through the elements in a collection. For example, displays each element in the collection. The simplest way to do this is to use

An iterator that is an object that implements the iterator interface or Listiterator interface.

An iterator that enables you to iterate through the elements of the collection or delete them. Listiterator inherits the iterator to allow two-way traversal of the list and modified meta

Of All the methods provided by the iterator and Listiterator interfaces are listed here by example.

(5) Comparator

TreeSet and TreeMap store elements in sorted order. However, this is done by the comparator to precisely define what sort order to follow. This one

Interfaces allow us to sort a collection in different ways.

Four Summary

The 1Java Collection Framework provides programmers with pre-packaged data structures and algorithms to manipulate them.

The 2 collection is an object that can hold references to other objects. The collection interface declares the actions that can be performed on each type of collection.

3 The classes and interfaces of the collection framework are in the Java.util package.

the 4Java Collection Class library separates the interface (interface) from the implementation (implementation).

The 5Java platform provides a new set of frameworks. The Java Collection framework consists primarily of a set of interfaces used to manipulate objects. Different interfaces describe a group of

different The data type.

In the following article we will describe in detail the various interfaces and implementation classes in the Java Collection framework, and will make some examples to learn more about the collection box

Frame, I refer to the example is Mu-class network of simulated students to choose the course function. Interested can take a look: http://www.imooc.com/video/2415.




Javase Introductory Learning 33:java Collection Framework Overview

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.