Below one is used when Single ArrayList have multiple types Objects and one object have count == 0 then it removed from pulseArray
Constants.java
public class ViewType {
public static final int PULSE = 101;
public static final int HEARTBEAT = 102;
}
BaseModel.java (This is Base Model)
public interface BaseModel {
int getViewType();
}
PulseModel.java (which implements with BaseModel)
public class PulseModel implements BaseModel {
@Override
public int getViewType() {
return Constants.ViewType.PULSE;
}
@SerializedName("PulseId")
@Expose
private String pulseId;
@SerializedName("Count")
@Expose
private String count;
}
Remove PulseModel object from pulseArray in which Count = 0
pulseArray.removeIf(
(BaseModel model) -> {
boolean remove = false;
if (model instanceof PulseModel) {
remove = (((PulseModel) model).getCount() == 0);
if (remove) {
//Success
}
}
return remove;
});
list.remove(object)is an O(n) operation. It gets executed O(n) times because it's in a loop. That gives O(n*n).remove(Object)is O(1), but Documentation proves your point.