Iterables.elementsEqual
is best choice:Iterables.elementsEqual
is enough to compare 2 List
s.
Iterables.elementsEqual
is used in more general scenarios, It accepts more general types: Iterable
. That is, you could even compare a List
with a Set
. (by iterate order, it is important)
Sure ArrayList
and LinkedList
define equals pretty good, you could call equals directly. While when you use a not well defined List, Iterables.elementsEqual
is the best choice. One thing should be noticed: Iterables.elementsEqual
does not accept null
To convert List to array: Iterables.toArray
is easer.
For unit test, I recommend add empty list to your test case.