I assume your O(n2) solution involves traversing one of the ArrayLists, and for each element, traversing the other ArrayList in its entirety to see if that element is contained.
This can be done in O(n) using hash tables. Start by adding each element from one of the lists to a hash table - this is O(n) total. Then, for the other list, for each element, look it up in the hash table - lookup is a constant-time operation. If it's in the hash table, add it to your result. Thus, we have total runtime of O(n) + O(n) = O(n).
If you're unfamiliar with hash tables, check out the resources here: https://www.geeksforgeeks.org/hashtable-in-java/