Collection Class day-11.3

Source: Internet
Author: User

A collection can be thought of as a container, as a red dress can be seen as a collection, and all Java class books can also be considered as a collection. It's easy to store objects in a collection in a collection, and it's easy to take them out of the collection, and they can be placed in a certain order. Different collection classes are available in Java that have different ways of storing objects and provide a way for users to iterate over the collection, add, delete, and find the specified object.

One: Collection class overview

Some collection classes are provided in the Java.util package, which is also known as a container. Refers to the container is not difficult to think of the array, the collection class and the array is different, the length of the array is fixed, the length of the collection is variable, the array is used to hold the data of the basic data class, the collection is used to hold the object's reference. Common collections include a list collection, set set, and map collection, where list and set inherit the collection interface, and each interface provides different implementation classes.

Two: Collection interface

The collection interface is the root interface in the hierarchy. The units that make up the collection are called elements. The collection interface is not typically used directly, but it provides methods for adding elements, deleting elements, and managing data. Because both the list interface and the set interface inherit the collection interface, these methods are common to the list set and set set. Common methods are as shown in the table:

Common methods for collection interfaces:

Method: Function Description:
Add (e E) Adds the specified object to the collection
Remove (Object o) Removes the specified object from the collection
IsEmpty () Returns a Boolean that determines whether the current collection is empty
Iterator () Returns an iterator to the element on this collection. Used to traverse objects in the collection
Size () Returns the int value that gets the number of elements in the collection

Collection Class day-11.3

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.