Java Collection Framework Overview

Source: Internet
Author: User

First, Introduction

1. Java Collection framework: In Java, a data structure is a collection of information that is organized in some form. They not only store data, they also support access and manipulation of data. These data structures are often referred to as the Java Collection framework.

2. Container: A data structure that can store other data or elements.

3. The Java Collection Framework supports two types of containers:

1), one is to store a collection of elements, referred to as the Set (collection).

2), another is to store a key/value pair, called a graph (map).

4, set frame diagram:

  

1) All interfaces and classes defined in the Java Collection framework are stored in the Java.util package.

2), all concrete classes in the Java Collection Framework implement the java.lang.Cloneable and Java.io.Serializable interfaces. As a result, their instances can be duplicated and serializable.

3), Java collection classes are mainly derived from two interfaces:Collection and map, Collection and map are the root interface of the Java Collection framework, the two interfaces contain some sub-interfaces or implementation classes.

4), the Java Collection Framework supports three main types of collections: Rule set (set), Linear table (list), and queue.

A, an instance of set is used to store a set of non-repeating elements. the elements in the collection can only be accessed based on the element itself (the reason why the elements in the collection are not allowed to be duplicated).

b, an instance of the list is used to store an ordered set of elements. The elements in the Access collection can be accessed based on the index of the element.

C, the queue instance is used to store objects that are processed in FIFO mode.

Second, the overall analysis

1, collection is an interface, is a highly abstracted collection, it contains the basic operation and properties of the collection . The collection contains the list and set of the two major branches.
1) List is an ordered queue, and each element has its index. The index value of the first element is 0. The list implementation class has LinkedList, ArrayList, Vector, Stack.

2) set is a set that is not allowed to have duplicate elements. The implementation class for set has Hastset and TreeSet. HashSet relies on HashMap, which is actually implemented through HashMap; TreeSet relies on treemap, which is actually implemented by TreeMap.

2, map is a mapping interface, that is, key-value key value pairs. Each element in the map contains "one key" and "key corresponding to value". Abstractmap is an abstract class that implements most of the APIs in the map interface. And Hashmap,treemap,weakhashmap are inherited from Abstractmap. Although Hashtable inherits from dictionary, it implements the map interface.

3, Next, see iterator. It is a tool for iterating through a collection, that is, we usually traverse the collection through the iterator iterator. We say that collection relies on iterator because the collection implementation class implements the iterator () function and returns a iterator object. Listiterator is specifically designed to traverse the list.

4. Then look at enumeration, which is the abstract class introduced by JDK 1.0. Functions, like iterator, also traverse collections, but enumeration are less powerful than iterator. In the above block diagram, enumeration can only be used in Hashtable, Vector, and stack.

5, finally, see Arrays and collections. These are the two tool classes that manipulate arrays and collections.

Third, collection interface and Abstractcollection class

1, Introduction: Collection interface is the root interface of processing object collection. The Abstractcollection class is a convenient class that provides a partial implementation of the Collegetion interface.

"interface"   boolean   // adds a new element to the collection O+addall (c:collection<? extends E >): Boolean   //Add all elements from collection C to this collection
+clear (): void //delete all elements in the collection
+contains (O:object): Boolean //If the collection includes elements O returns true
+containsall (c:collection<?>): Boolean //returns True if the collection contains all the elements in C
+equals (O:object): Boolean //returns True if the collection equals another collection
+hashcode (): int //return set hash code
+isempty (): Boolean //If the collection does not include any elements return O
+iterator (): iterator<e> //The iterator used to return the collection of heavy elements
+remove (O:object): Boolean //delete element from collection O
+removeall (c:collection<?>): Boolean //delete all elements of collection C from the collection
+retainall (c:collection<?>): Boolean //reserved for C and all elements in the collection
+size (): int //Returns the number of elements of the collection
+toarray (): object[] //Returns an array of elements in the collection Object

    

Overview of the Java Collection Framework

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.