Java Collection Learning (ii) Collection architecture

Source: Internet
Author: User
Tags abstract

First, we explain the collection. Let's look at the diagram of some of the framework classes in collection:

Collection is an interface, and its main two branches are:List and Set.

Both the list and set are interfaces, and they inherit from collection. The list is an ordered queue, and the list can have duplicate elements , and set is a collection of mathematical concepts, and there are no duplicate elements in the set!
Both the list and set have their respective implementation classes.

For convenience, we abstract the Abstractcollection abstract class, which implements most of the functions in the collection, so that in the collection implementation class, we can eliminate duplicate encoding through inheritance abstractcollection. Both Abstractlist and abstractset inherit from Abstractcollection, the specific list implementation class inherits from Abstractlist, and the set's implementation class inherits from Abstractset.

In addition, there is a iterator () function in the collection, which is the function of returning a iterator interface. Typically, we traverse the collection through the iterator iterator. The listiterator is specific to the list interface and returns a Listiterator object through Listiterator () in the list interface.

Next, we look at the introduction to each interface and abstract class, and then we have a detailed understanding of the implementation class.

1 Collection Profile

The definition of collection is as follows:

Interface collection<e> extends Iterable<e> {}

It is an interface, a highly abstracted collection that contains the basic operations of the collection: adding, deleting, emptying, traversing (reading), being empty, getting the size, protecting an element, and so on.


All subclasses of the collection interface (both direct subclasses and indirect subclasses) must implement 2 constructors: constructors with no parameters and constructors with parameters of collection. A constructor with parameters that can be used to convert a collection type.

Collection API
Abstract Boolean         Add (E object)
Abstract Boolean         addall (collection<? extends E > collection) abstract
void Clear            ()
Abstract Boolean         contains (object)
abstract Boolean         Containsall (collection<?> Collection)
abstract Boolean         equals (object)
abstract int             hashcode () abstract
boolean         IsEmpty () abstract
iterator<e>     iterator ()
Abstract Boolean         Remove (object)
abstract Boolean         removeall (collection<?> Collection)
Abstract Boolean         retainall (collection<?> collection)
abstract int             size ()
abstract <T> t[]         toArray (t[] array)
abstract object[]        ToArray ()

2 List Introduction

The list is defined as follows:

Interface list<e> extends Collection<e> {}

A list is an interface that inherits from collection, which is one of the collections. The list is an ordered queue, and each element in the list has an index; the index value of the first element is 0, and the index value of the subsequent element is +1. Unlike set, duplicate elements are allowed in the list.
The official description of the list is as follows :

A List is a collection which maintains of ordering for its elements. Every element in the List has a index. Each element can thus is accessed by its index being zero Normally, Lists allow duplicate elements, as compared to Sets, where elements have to be unique.

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.