0

I know there are many similar questions that look like mine, but I just wanted to ask for my clarification purposes. Let's say I have 2 lists, which looks like this:

VO vo1 = new VO("This"); 
VO vo2= new VO("is");
VO vo3= new VO("first");
VO vo4= new VO("list");
List<VO> volist= new ArrayList<>(); // first list
volist.add(vo1);
volist.add(vo2);
volist.add(vo3);
volist.add(vo4);

List<String> str = new ArrayList<>();
str.add("This");
str.add("is");
str.add("first");

Is is possible to loop these 2 list to find out the differences (i.e. "list" is not present in the str list)? How should I do this?

prog rice bowl
  • 788
  • 3
  • 19
  • 36
  • possible duplicate of [Efficiently compute Intersection of two Sets in Java?](http://stackoverflow.com/questions/7574311/efficiently-compute-intersection-of-two-sets-in-java) **Not exact, since you're using Lists, but it's close** – MightyPork Mar 29 '14 at 10:12
  • lol, that was why my first line :) btw, the answer looks complicated. :x – prog rice bowl Mar 29 '14 at 10:16
  • It looks complicated because it IS complicated. If you don't care about efficiency, you could use two for loops (go through list elements) and check if the other list contains them all or not. – MightyPork Mar 29 '14 at 10:38

1 Answers1

0

Create a HashSet<String>. Iterate over the VO list, and add the String value that each VO contains to the set. Then call removeAll() on the set with the str list as argument. Done.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255