I am not abe to execute the program..please help
import java.util.*;
public class AA { public static void main(String[]args){ String[] things = {"hat ","pencil ","bottle ","laser"}; List<String> list1 = new ArrayList<String>();
//add items to the list for(String x:things) list1.add(x); String[] morethings = {"pencil","bottle"}; List<String> list2 = new ArrayList<String>(); //add items to the list for(String y:morethings) list2.add(y); //print list 1 for(int i=0;i<list1.size();i++){ System.out.printf("%s",list1.get(i)); } editlist(list1,list2); System.out.println(); //print list 1 for(int i=0;i<list1.size();i++){ System.out.printf("%s",list1.get(i)); } } public static void editlist(Collection<String> l1,Collection<String> l2){ Iterator<String>it=l2.iterator(); while(it.hasNext()){ if(l2.contains(it.next())) it.remove(); } }
}
Do you want to remove the elements the elements from list1 which are present in list2?
yes sir..i was expecting the answer like this
hat pencil bottle laser hat laser
but its displaying, hat pencil bottle laser hat pencil bottle laser..
So please help me to get the output..
eagerly waiting for ur reply..pls respond back sooon