[Java learning notes] Collection framework I, java learning notes

Source: Internet
Author: User

[Java learning notes] Collection framework I, java learning notes

 

Collection class:

An object is used to encapsulate special data. An object needs to be stored if the number of objects is uncertain.

The collection container is used for storage.

Set features:

1. the container used to store objects.

2. The length of the set is variable.

3. Basic data type values cannot be stored in a collection.

 

Because of the different internal data structures, a collection container has a variety of specific containers that are constantly extracted to form a collection framework.

The top layer of the Framework isCollectionInterface.

Common methods of Collection:

1. Add

Boolean add(E e);

BooleanaddAll(Collection<? extends E> c);

2. Delete

   Boolean remove (Object obj );

BooleanremoveAll(Collection<?> c); // Delete the same elements from the two sets that call removeAll.

Void clear (); // clear

3. Judgment

Boolean contains (Object obj );

BooleancontainsAll(Collection<?> c);

Boolean isEmpty ();

4. Obtain

  Int size ();

Iterator iterator (); // method of retrieving elements: Iterator.

This object must depend on a specific container because the data structure of each container is different.

Therefore, the iterator object is implemented internally in the container.

For container users, the specific implementation is not important. You only need to obtain the object of the implementation iterator through the container, that is, the interator method.

This object is similarCapture clips from doll game consoles.

 

The Iterator interface is a public interface for retrieving elements from all Collection containers.

 

5. Others

    BooleanretainAll(Collection<?> c); // Take the intersection, retain the same elements of the specified set, and delete different elements. Unlike removeAll.

Object [] toArray (); // converts a set into an array.

 

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.