Java – * * copy * * and * * addall * * what’s the difference?
•
Java
1) Are there any differences between these two keywords for collection elements? (copy these elements to another collection and add them to another collection)
Solution
Yes, a little different
From Java docs:
Copy: copies all elements from one list to another After the operation, the index of each copied element in the target list will be the same as that in the source list The destination list must be at least as long as the source list If it is longer, the remaining elements in the target list are not affected
Example: copy [1,2,3] to [4,5,6,7,8] = > [1,3,8]
Addall: adds all specified elements to the specified collection
Example: [1,3] to [4,8] = > addall [4,8,1,3]
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码