I need to do something like this...
Collection<T> myCollection; ///assume it is initialized and filled
for(Iterator<?> index = myCollection.iterator(); index.hasNext();)
{
Object item = index.next();
myCollection.remove(item);
}
Obviously this throws ConcurrentModificationException...
So I have tried this but doesn't does seem elegant/efficient and throws a Type safety: Unchecked cast from Object to T warning
Object[] list = myCollection.toArray();
for(int index = list.length - 1; index >= 0; index--) {
myCollection.remove((T)list[index]);
}