Suppose I have three lists:
list1 = a, c, d, r, t
list2 = a, d, t
list3 = a, r, d
Then list2 is contained in list1 but list3 is not because it is not in the same order.
I checked isSubCollection() from CollectionUtils in Apache Commons, and the containsAll() method, but it seems that they don’t consider order.
This algorithm is linear and requires only 1 iteration in
suplist.UPDATE
If you use linked lists,
getoperation may run in O(n). So you can use 2 iterators:But it looks uglier.