I have implemented a trim
method which removes objects having empty properties.
This list has average size of 3 or so. Probably, the max length is 7 or 8.
I wonder which of these implementations is faster:
Implementation 1
private void trim() {
Iterator<Child> iterator = mList.iterator();
while (iterator.hasNext()) {
Child child = iterator.next();
if (child.isEmpty()) {
iterator.remove();
}
}
}
Implementation 2
private void trim() {
for (Child child : mList) {
if (child.isEmpty()) {
mList.remove(child);
}
}
}
Implementation 3
private void trim() {
for (int i = 0; i < mList.size(); i++) {
IChild child = mList.get(i);
if (child.isEmpty()){
mList.remove(i);
}
}
}