I understand that ArrayList<>'s are fastest for searching (O(1) vs. O(n)) and LinkedList<>'s are fastest for inserting & deleting (O(1) vs. O(n)).
My question is, if using a combination of these two, what is the optimal method to check many lists (>2) for common elements?
Current Method Using three lists and an iterative method:
out:
for(int a = 0; a < list1.size(); a++) {
for(int b = 0; b < list2.size(); b++) {
for(int c = 0; c < list3.size(); c++) {
if(list1.get(a) == list2.get(b) && list1.get(a) == list3.get(c) ) {
System.out.println(list1.get(a)); // list2.get(b) or list3.get(c) could have been subbed
break out;
}
}
}
}
How can this be optimised for efficiency?
