Java Q & A

Source: Internet
Author: User

1. What is the difference between

I.  New Arraylist<integer>(Arrays.aslist (IA)); List<Integer> list2 = Arrays.aslist (IA);
 i.  New arraylist<integer> (Arrays.aslist (IA))
    • The new is an ArrayList independent copy of the original one.
    • Although you create the wrapper using Arrays.asList , it's used only during the construction of the new and is ArrayList Garbage-col lected afterwards.
II. Arrays.aslist (IA)
    • Array ia and creates a wrapper that implements List<Integer> , which makes the original array as a list.
    • Nothing was copied at all, with a single wrapper object is created.
    • Operations on the list wrapper is propagated to the original array – if you shuffle the list wrapper, the original array is shuffled; If you overwrite a element, it gets overwritten in the original array, etc.
    • Some list operations aren ' t allowed on the wrapper, like adding or removing elements from the List-no resize.
    • List wrapper doesn ' t extend ArrayList -- ArrayList S has their own, internal array, which they is able to resize.

2.

Java Q & A

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.