"Java Learning Notes" collection Framework Ⅰ

Source: Internet
Author: User

The origin of the collection class:

      Objects are used to encapsulate unique data, and objects need to be stored if the number of objects is indeterminate.

is stored using the collection container.

Set Features:

1. A container for storing objects.

2, the length of the set is variable.

3. The base data type value cannot be stored in the collection.

Collection container because of the internal data structure, there are a number of specific containers, constantly upward extraction, forming a set of framework .

The top layer of the frame is the Collection interface.

Common methods of collection:

1. Add

Boolean Add (Object obj);

Boolean AddAll (Collection coll);

2. Delete

   Boolean remove (Object obj);

Boolean RemoveAll (Collection coll); Removes the same element from the two collection from the collection that calls RemoveAll.

void Clear (); Clear

3. Judgment

Boolean contains (Object obj);

Boolean Containsall (Collection coll);

Boolean isEmpty ();

4. Get

  int size ();

Iterator Iterator (); The way to remove an element: an iterator.

The object must depend on the specific container, because each container has a different data structure.

So the iterator object is internally implemented in the container.

For a container user, a specific implementation is not important, as long as the object is obtained through the container to the iterator of the implementation, that is, the Interator method.

The object, similar to the clip in the Scratching Doll game machine .

The iterator interface is the common interface for extracting elements from all collection containers.

5. Other

    Boolean Retainall (Collection coll); Takes the intersection, preserves the same elements as the specified collection, and removes the different elements. Contrary to the RemoveAll function.

Object[] ToArray (); Converts a collection to an array.

"Java Learning Notes" collection Framework Ⅰ

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.