ARRAYLIST,LINKEDLISTD and other containers when using the attention point:

Source: Internet
Author: User

1, to the two list (including other similar containers), if you add an element to the inside (reference data type), then this list is stored in the object's reference;

If you want to avoid this phenomenon can be: In addition to the new element without direct pressure, the existing objects copied a copy of the press in (I recommend if you write the class is best to implement the Cloneable interface, overload the Clone function);

2. These two guys are not allowed to traverse:

for (LinkedList ele:elelist) visit ele;

When you delete more than one element, it will throw an exception, of course, if you can guarantee a loop down to remove only one element, and remove the direct jump out of the loop is no problem. Now provides a way to solve the first situation: at the time of the traversal of all the elements to be deleted into a temporary container (temp_container), and so on after the traversal of the call RemoveAll (Temp_container) is done.

ARRAYLIST,LINKEDLISTD and other containers when using the attention point:

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.