I have an application that generates many arraylists, stored in a collection. All the arraylists will always have a common element.
I need to work out which is the common element. I managed this with two lists and using List.contains(...) but need to scale this to many lists.
How can I do this?
Use a hashtable that maps unique elements in each arraylist to its frequency (ie even if there are multiple occurrences of an element in the same arraylist it has to be incremented only once). Iterate through the hashtable until the value is equal to the number of arraylists. The corresponding key is the element we are looking for.