Container (J2SE learning essay One)

Source: Internet
Author: User
Container

1. Container: An instance of a series of classes provided by the Java API for storing objects in a program. (The object is stored, not the underlying data type: Because the data on the stack can be emptied at any time)

2. The collection interface defines a method for saving a set of objects, and its sub-interface set and list define the storage mode separately: A, set class and its subclasses are stored, the storage objects are unordered and non-repeatable; B, the list class and its subclasses are stored, The stored objects are ordered and repeatable. (The repetition here is between two objects equals ())

3. The map interface defines a method for storing key (key)-value mapping pairs.

4, the container class object when calling remove, contains and other methods, you need to compare the object is equal. This involves the Equals method and the Hashcode method of the object type, and for custom types, you need to override the Equals and Hashcode methods to implement custom object equality rules. (Note: Equal objects should have equal hash codes.) (the default method of equals in Java.lang.Object is to determine whether two objects are the same object.) )

5. Iterator interface: All containers that implement the collection interface have a iterator method for returning an object that implements the iterator interface. This object is called an iterator to facilitate the traversal of elements within a container. The iterator interface defines the following methods:

Boolean hasnext ();//Determine whether the right side of the cursor is an element

Object Next ()//returns the element to the right of the cursor and moves the cursor to the next position

Void remove ();//delete the element to the left of the cursor, which can only be executed once after the next execution

The iterator of the middle reaches the following chart:

Note: The Remove method of the Iterator object is the only safe way to remove an element during an iterative process.

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.