I am looking for an efficient way to search whether all elements in arraylist<string> 1 are present in arraylist<string> 2. If not get them all in a separate list. Thank you !
However you need to consider: can the lists contain duplicate values? If so, does the number of times a duplicate occurs have an effect on the answer? In that case, a HashSet probably won't help, but a HashMap might.
Hi , there are more than 40,000 entries minimum but they are all unique. So redundant data is not an issue. IT should be effecient and less time consuming. Those are bunch of paths. Thanks !
The costly part is to check wether list2 contains an element from list1 (each call to contains() potentially has to check list2.size() elements). You can improve this by copying list2 into a HashSet, because the contains() method of the HashSet has near constant time cost. So you'd look at something like: