Java knowledge Summary (2) -- container

Source: Internet
Author: User

1. Container: A series of class instances provided by Java APIs, used to store objects in programs. (Objects are stored, not basic data types: Data on stacks may be cleared at any time)

2. The collection interface defines the method for storing a group of objects. Its Sub-interfaces set and list define the storage method: When a, set and its sub-classes are stored, its storage objects are unordered and repeatable. When B, List classes and their subclasses are stored, their storage objects are ordered and repeatable. (Here the repetition is the mutual equals () between two objects ())

3. The map interface defines how to store "key-value ing pairs.

4. When a container object calls methods such as remove and contains, You need to compare whether the objects are equal. This involves the equals and hashcode methods of the object type. For custom types, you need to override the equals and hashcode methods to implement custom object equality rules. (Note: equal objects should have equal hashcodes .) (The default equals method in Java. Lang. object is to determine whether two objects are the same .)

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

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

Object next (); // returns the element on the right of the cursor and moves the cursor to the next position.

Void remove (); // Delete the element on the left of the cursor. This operation can only be performed once after the next operation is completed.

Note: The Remove Method of the iterator object is the only safe method for deleting elements during iteration.

6. Supplement to array and collection traversal:

7. Set interface:

Note: The set interface can complete operations in a mathematical set.

8. List interface:

 

9. map interface:

Note: key values cannot be repeated. They are determined using the equals and hashcode methods.

10. Auto-boxing/unboxing (automatic packaging and unpacking) (available only after java1.5)

Automatic packaging and unpacking at the right time: A. automatic packaging is to automatically convert the basic data type to the corresponding object; b. Automatic unpacking is to automatically convert the corresponding basic data type object to the basic data type.

11. Generic:

Container structure description:

 

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.