1

I made two string lists and i wanted to remove from the first one the words that are also on the second list. I have errors on "it.remove();"

String []names={"one","two","three","four","five"};
    List<String> list=Arrays.asList(names);
    List<String> list2=new ArrayList<String>();
    list2.add("apple");
    list2.add("one");
    list2.add("five");
    list2.add("six");
    Iterator<String>it=list.iterator();
    while(it.hasNext()){
        if(list2.contains(it.next())){
            it.remove();
        }
    }
    System.out.print(list);
T4l0n
  • 595
  • 1
  • 8
  • 25

0 Answers0