0
List<List<String>> list1 = new ArrayList<List<String>>();
List<List<String>> list2 = new ArrayList<List<String>>();

the values in the list1 = [[cat,01,animal] , [mouse,02,animal] , [dog,03,animal] , [eagle,01,bird]]
the values in the list2 = [[mouse,02,animal], [eagle,01,bird]]

How can i output the common elements(mouse,02,animal and eagle,01,bird)
and the different elements (cat,01,animal and dog,03,animal) using java.

Guys i don't think this is duplicate of comparing two list. Its list> comparison.

  • 4
    Why do you have an inner list if it only contains a single element? – Tunaki Jun 27 '16 at 12:22
  • well i have edited the question .. –  Jun 27 '16 at 12:28
  • In future basic Java questions, please do not anymore use `[java-ee]` tag. Moreover, please carefully read tag descriptions before picking tags. – BalusC Jun 27 '16 at 12:28
  • How is mouse,2,mouse a common element in your example? – J Fabian Meier Jun 27 '16 at 12:30
  • Alright ! The questions which is tagged along with this question as duplicate has the comparison between two arraylist or lists. Its the list> –  Jun 27 '16 at 12:31
  • Could you please correct or explain your example in the question (regarding mouse,2,mouse)? – J Fabian Meier Jun 27 '16 at 12:34
  • Have you actually tried to use retainAll? From experience, this should work. – J Fabian Meier Jun 27 '16 at 12:37
  • retainAll is giving me empty output.. Where as removeAll gives me all the elements from the list1 –  Jun 27 '16 at 12:43
  • The solutions given in the two duplicate questions [appear to be working for me](http://ideone.com/Fb6K1o) -- it's unclear to me why they aren't working for you. In particular, it shouldn't really matter if you're comparing a `List` or a `List>` -- the same code works for both. If I were you, I would consider editing your post to include the actual code you've tried using based on the linked posts and what the output is. You may have an unrelated issue or misunderstanding in your code. – Michael0x2a Jun 27 '16 at 18:17

0 Answers0