The difference between removeAll() and clear() in ArrayList
boolean removeAll(Collection<?> c) Remove all elements of a given collection from the list (optional action).
removeAll(Collection< ?> C) can pass a Collection type parameter, which is intended to clear the current list with all the elements contained in the passed Collection. That is to say, removeAll is actually an operation that first intersects with c and then fills.
And clear() clears all the elements in the current list. Although the names are somewhat similar, they are actually completely different operations.
- removeAll is similar to retainAll by taking the intersection of the current list and the incoming Collection. That is to say, the current list does not necessarily contain all the elements of the incoming Collection. The incoming Collection may contain some elements that are not in the current list, but it does not affect the work of removeAll and retainAll. Most collections can use these two methods and pass the Collection as a parameter, not just to List or ArrayList, but to be aware of element type compatibility. RemoveAll removes all elements from the current list that intersect with the passed Collection, rather than just removing the first element from the list, as removeAll does. So, when you want to removeAll the element a from the list, you can use removeAll:
RetainAll is similar to removeAll in that when an element a is included in the passed Collection, multiple a’s in the list retain both removeAll and retainAll’s behavior depending on the equals() method. You must be aware of the changes
‘s behavior when using
boolean retainAll(Collection<?> c) Keep only those elements of this collection that are also included in the specified collection (optional action). In other words, remove all elements from this collection that are not included in the specified collection.
- [How to Fix]Element is not attached to the page document record
- Vector series in actual C + +_ To_ fit()
- How to Check Password Modification Complexity
- How to Create Threads in Linux
- [Solved] Linux gcc Compile Error: unknown type name ‘bool‘
- Linux Drive Error: Error: function declaration isn’t a prototype
- Git: How to delete stash content
- Linux apt-get update Error: Error in `appstreamcli‘: double free or corruption … Aborted (core dumped)
- C Language Compilation Error: variably modified ‘* *’ at file scope
- [Solved] Ubuntu18.04 Px4 (xtdrone) gazebo joint simulate error
- [Solved] Error :: You must put some ‘source‘ URIs in your sources.list
- Common configuration methods of nginx
- [Solved] SSH Error: ECDSA host key for xxx has changed and you have requested strict checking.
- [Solved] yum Error: Error: rpmdb open failed
- [Solved] Find command error: find: missing “- exec” parameter solution
- [Solved] docker: Error response from daemon: OCI runtime create failed: container_linux.go:380
- [Solved] Linux C++ warning: ISO C++ forbids converting a string constant to ‘char*‘ [-Wwrite-strings]
- [Solved] CentOS Use Yum to install dependency: error: rpmdb open failed
- Clang Error: error: cannot specify -o when generating multiple output files
- How to Delete New Memory in Vector