
I am not able to execute the program..please help
package Intermediate;
import java.util.*;
public class Arrayedit { 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=l1.iterator(); while(it.hasNext()){ if(l2.contains(it.next())) it.remove(); } } }
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.