![]() |
Collection means a set of different classes and interfaces are group together into a single unit that has similar functions are called collection and framework we know very that provides a predefined architecture to represents and manipulate collections in java. Here we will be discussing discuss out how to find the intersection between the two collections i.e Remove all the elements from the first collection if it is not available in the second collection. In this article we will use two collection framework classes vector class and ArrayList class to find the intersection between the two collection. Methods:
Approach 1:
Example: Java
Output
1 2 3 Time Complexity: O(n) Space Complexity: O(n) Approach 2: Using Vector.retainAll() method
Example: Java
Output
1 2 3 Time Complexity: O(1) Auxiliary Space: O(1) |
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 9 |