list1:[1,2,3,4,5]
list2:[1,2,3]
How to check if list2 is a subset of list1? I tried containsAll() but it gives true as long as the elements in list 2 are present in list1. I want the same order as criteria and not just the elements.
Use this:
boolean contains(List<?> list, List<?> sublist) {
return Collections.indexOfSubList(list, sublist) != -1;
}
http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#indexOfSubList(java.util.List,%20java.util.List)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With