I have a String List.On a satisfied Condition ,I need to group strings and remove those before iterating. For example;
List<String> test = new ArrayList();
List<String> newLst = new ArrayList();
test.add("A1");
test.add("A2");
test.add("A3");
test.add("A1B1");
test.add("C1");
for(String s: test){
if(s.startsWith("A"){
newLst.add(s);
test.remove(s);
}
}
Once A1 reaches the loop,collect related string in new list and remove it from existing.
Getting Concurrent Modification exception.Kindly help to solve this.
Output: newLst: A1,A2,A3 test : A1B1,C1
newLst : A1B1 test:C1
newLst : C1