package silverbullet; import java.util.ArrayList; public class StringProcessing { public static ArrayList<String> list=new ArrayList<String>(10); public static ArrayList<String> deleted=new ArrayList<String>(10); public void set() { list.add("hello"); list.add("hi"); list.add("hello"); list.add("bye"); } public void print() { for(int i=0;i<deleted.size();i++) { System.out.println(deleted.get(i)); } } public static void main(String[] args) { StringProcessing sp=new StringProcessing(); sp.set(); for(Object l:list) { int c=0; String s=l.toString(); for(int i=0;i<(list.size()-c);i++) { if(s==list.get(i+1)) { list.remove(i+1); deleted.add(s); c=c+1; } } } sp.print(); } }
i tried lot, changed code. but getting the exception of "ConcurrentModificationException"
my concept of this program is to print the items which are duplicated in the ArrayList named list, and storing the duplicates in the new ArrayList named deleted.
Help me fix this problem