Common method for collection interface collection foreach Iterator iterator

Source: Internet
Author: User

Interface for collection interface single-column collection
List has indexed order
Set no index unordered
Abstractcollection is an abstract parent class that implements the collection interface
collection<> C = new arraylist<> ();
Polymorphism can only be used by the parent class method, not the subclass-specific method

A general method of collection
Add added ()
Delete Remove ()
Empty collection Clear ()
Determines whether an element is empty IsEmpty
Determine if an element exists contains ()
The length of the collection size ()

Enhanced for foreach Traversal container has no index

for (data type TEMP variable: The collection that needs to be traversed) {
You can print variables directly
}

Iterator Iterator
To create an iterator object for a collection
Use Hasnext to determine if there is a next element
Next gets the next element

Concurrency modification Exceptions
In the iterative process, the collection can not add elements to itself or delete elements, but can use iterators to add or change

Iterate and iterate distinguish iterative emphasis on repetition of actions
Shuffle the method Collections.shuffle (pass a set);

        

Common method for collection interface collection foreach Iterator iterator

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.