![]() |
The removeAll() method of Java Collection removes those elements from the collection that are contained in the collection which is given as an argument to function. Syntaxboolean removeAll(Collection<?> c);
Parameters:
Return Type:It returns a boolean value. It returns true if the calling collection was modified by the removeAll() method else it returns false. Example of Collection removeAll() methodBelow is the implementation of the above method: Java
Output
Original List: [1, 2, 3, 4] List containing elements to be removed from the calling collection(list1): [2, 4] Elements removed from List1: true Modified list1 after deletion: [1, 3] Example 2:Another example where the collection passed as an argument doesn’t contain any element which could be deleted in original collection. Java
Output
Original List: [1, 2, 3, 4] List containing elements to be removed from the calling collection(list1): [7, 8] Elements removed from List1: false Modified list1 after deletion: [1, 2, 3, 4] |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |