I have ArrayList, from which I want to remove an element which has particular value...
for eg.
ArrayList a=new ArrayList
Try below code :
public static void main(String[] args) throws Exception{
List l = new ArrayList();
l.add("abc");
l.add("xyz");
l.add("test");
l.add("test123");
System.out.println(l);
List dl = new ArrayList();
for (int i = 0; i < l.size(); i++) {
String a = l.get(i);
System.out.println(a);
if(a.equals("test")){
dl.add(a);
}
}
l.removeAll(dl);
System.out.println(l);
}
your output :
[abc, xyz, test, test123]
abc
xyz
test
test123
[abc, xyz, test123]