Collection framework Introduction

Source: Internet
Author: User

Collection framework Introduction

Java Collection framework

Collection framework:

① The so-called framework is a collection of class libraries. A collection framework is a unified architecture used to represent and operate a set. It contains interfaces and classes that implement a set;

② Different collection classes in the Collection framework have different data structures. Therefore, you must select different collection classes based on application performance requirements during use;

③ Collection classes are stored in the java. util package. During programming, a large number of collection classes and related interfaces are used;

A) Iterable: iterator interface;

B) Collection: Class Set interface;

C) List: List interface;

D) Set: DataSet interface;

E) Queue: Queue;

F) Map: Key-value pair combination ing table;

 

Iterable Interface:

① This interface allows the object to become the target of the "foreach" statement, that is, the set object can be iterated;

② Collection is a sub-interface of Iterable, so all class set objects can be accessed iteratively, but Map-based objects cannot;

③ Method:

Iterator <T> iterator ()

Function: returns an iterator that iterates on a group of T-type elements;

The Iterator is the class object that implements the Iterator/ListIterator interface. You can traverse the class set and access each element in the operation;

ListIterator extends the parent interface Iterator, which allows two-way traversal of sets and allows you to modify and delete elements;

 

Collection Interface:

Method defined by the Collection interface of the class set:

① Int size ()

② Boolean isEmpty ()

③ Booean contains (Object o)

④ Iterator <E> iterator ()

⑤ Object [] toArray ()

⑥ Boolean add (E e)

7. boolean remove (Object o)

⑧ Void clear ()

 

List, Set, Map

① The List interface extends the Collection feature: ordered and repeatable;

② The Set interface extends the Collection feature: unordered and repeatable;

③ Map is an object that stores keyword/value pairs. Given a keyword, You can query it to obtain its value. Both the keyword and value can be objects. Collection ing is not a sub-interface of Collection. Therefore, it cannot be traversed by the iterator itself;

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.