The difference between the List's Add () and AddAll ()

Source: Internet
Author: User
Tags addall

Add is to store the incoming parameter as an item in the current list, even if you pass in a list and only add 1 elements to the current list.
AddAll is to pass in a list, adding all the elements of this list to the current list, that is, the number of elements that the current list adds to the size of the incoming list
That
   AddAll (Collection C)   Add (int index, ELELEMT e)--------------------------------------   AddAll (Collection c)
This method adds all the elements in the collection to the end of the list, in order of the elements returned by the iterator that specifies collection. If the specified collection is modified while this operation is in progress, the behavior of this operation is indeterminate (which means that if the specified collection is this list and the list is non-null, the behavior of the call is indeterminate).
C contains the collection of the elements to be added to this list
Return TRUE if this list has been changed due to a call
NullPointerException: If the specified collection is null
Throws
Eg:collection result = new ArrayList (); Collection list = new ArrayList (); Analysis:  result.addall (list);   Add each element in the list to result, result.size () = = List.size () result.add (list);       Add list as an element to result, then Result.size () is 1


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The difference between the List's Add () and AddAll ()

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.