Collection framework Summary-collection

Source: Internet
Author: User

1. The collection framework acts as a container for processing objects. The basic interface is collection. Compared with arrays, the collection framework can only store objects, but its length is variable. The relationship diagram of the Collection framework is as follows:

The main content is list, set, map,

The elements stored in the list set are ordered, and the elements can be duplicated and indexed.

The elements stored in the Set set are unordered and cannot be repeated.

Map is a set that develops a storage ing relationship based on set.

2. Explain the collection method, that is, the method shared by the collection framework.

Boolean add (E element)

Purpose: add element objects to a collection.

Return: If the set is changed, true is returned. Otherwise, false is returned.

Iterator ()

Purpose: return iterator for element operations.

Return: iterator

???? |-Hasnext ()

???????? Purpose: Check whether an element exists in the set.

???????? Return: returns true if an element exists at the end of the set. Otherwise, false is returned.

???? |-Next ()

???????? Purpose: access the next element.

???????? Return: If the set still has an element, return the next one. If it does not exist, use nosuchelemmentexception.

???? |-Remove ()

???????? Purpose: Delete the element returned by the last call of next (), that is, to delete an element, the element must be crossed first.

???????? Return: void

Int size ()

Purpose: return the number of elements in the set.

Boolean isempty ()

Purpose: Check whether the set is empty.

Return: null returns true, non-null returns false

Boolean contains (Object OBJ)

Purpose: Check whether an element exists in the set.

Return: If yes, true is returned; otherwise, false is returned.

Boolean containaall (collection <?> C)

Purpose: Check whether all elements of a set exist in the set.

Return: If yes, true is returned; otherwise, false is returned.

Boolean equals (object other)

Purpose: Check the equality of the set.

Returns true if they are equal. Otherwise, false is returned.

Boolean addall (collection <? Extends E> C)

Purpose: add an element in a set to this set. The element to be added must be of the subclass type of the existing element.

Return: True is returned for successful addition, and false is returned for failed addition.

Boolean remove (Object O)

Purpose: remove a single instance of a specified element from this collection. If yes (optional ).

Return: True is returned for success, false is returned for failure

Boolean removeall (collection <?> C)

Purpose: Remove all elements in the collection that are also included in the specified collection (optional ).

Return: True is returned for success, false is returned for failure

Boolean retainall (collection <?> C)

Purpose: retain only the elements in the collection that are also included in the specified collection (optional ). Intersection

Return: True is returned for success, false is returned for failure

Object [] toarray ()

Purpose: return an array containing all elements in the collection.

Return: True is returned for success, false is returned for failure

<T> T [] toarray (T [])

Purpose: return an array containing all elements in the collection. The runtime type of the returned array is the same as the runtime type of the specified array.

Return: An array is returned successfully. If not, null is returned.

Collection framework Summary-collection

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.