Set.retainAll()
is how you find the intersection of two sets. If you use HashSet
, then converting your ArrayList
s to Set
s and using retainAll()
in a loop over all of them is actually O(n).
More Related Contents:
- How to calculate the intersection of two sets? [duplicate]
- Removing duplicates from arraylist using set
- O(3^n) exponential time complexity [closed]
- Intersection and union of ArrayLists in Java
- Cartesian product of an arbitrary number of sets
- Obtaining a powerset of a set in Java
- Is a Java hashmap search really O(1)?
- What is the difference between Set and List?
- How to convert an Array to a Set in Java
- Java Set retain order?
- Big-O summary for Java Collections Framework implementations? [closed]
- Picking a random element from a set
- Getting an element from a Set
- What is the fastest way to compare two sets in Java?
- Different types of thread-safe Sets in Java
- Stack with find-min/find-max more efficient than O(n)?
- Efficiently compute Intersection of two Sets in Java?
- Efficient intersection of two List in Java?
- Iteratively compute the Cartesian product of an arbitrary number of sets
- Get unique values from ArrayList in Java
- Why doesn’t java.util.Set have get(int index)?
- What is the complexity of this simple piece of code?
- Why does TreeSet throw a ClassCastException?
- HashSet contains duplicate entries
- Cartesian product of streams in Java 8 as stream (using streams only)
- Java- Intersection point of a Polygon and Line
- Why does my TreeSet not add anything beyond the first element?
- Java HashSet with a custom equality criteria? [duplicate]
- Convert Set to HashMap
- Performance and Memory allocation comparison between List and Set