Sorry please ignore my previous comment of sorting out the objects in to another list and then use List.removeAll() because that dont work. Let me explain my requirement-
My program :-
List list =getList(); // A method that will return a list of Integer //objects [1,2,3,4]
for(int i=0;i<list.size();i++){
Object temp=list.get(i);
If(temp instanceof Integer){
Integer id=(Integer) temp;
// Business logic to get parent-attachment document numbers for this id
//if those ids present in this list remove at this point from the underlying //list , here I cant do because in that case I cant use for loop to iterate //I must use iterator and that will throw concurrent modification //exception. So mark these documents as
String.
List paList=getParentAttachment(id);
for(int j=0;j<paList.size();j++){
Integer doc=(Integer) paList.get(j);
if(list.contains(
doc)){
int position=list.indexOf(doc);
list.remove(position);
list.add(position,"String");
}
}
}
}
// Remove all string objects from list
Iterator it=list.iterator();
while(it.hasNext()){
Object obj=it.next();
if(obj instanceof String)
it.remove();
}
I know this is crud but i dont see any other solution, may be a design
pattern?