sets, subsets and palindrome in java
How do I check if a list开发者_C百科 is a subset of another list in java? How do I check using two ListIterators to return true if the given list is a palindrome list.
A palindrome is the same front to back as it is back to front. Given a list you can retrieve listIterators starting at a given index in the list. Add this to the fact that listItarators have next()
and previous()
methods, I am confident that you'll find a way to compare the items in the list to see if the list is in fact a palindrome or not.
containsAll(Collection c) can solve your 1st problem.
For the 2nd problem, use reverse(List list) from Collections class. Take one iterator on the real list & other on reversed list and compare 2 lists element by element.
To question one see java.util.Set#containsAll.
精彩评论