ListResult (@NotNull ChildInfo child) { List<ChildInfo> newChildren = new ArrayList<>(children.size() + 1); int id = child.getId(); int toRemove = ObjectUtils.binarySearch(0, children.size(), mid -> Integer.compare(children.get(mid).getId(), id)); if (toRemove < 0) { // wow, the child is not there return this; } else { for (int j = 0; j < toRemove; j++) { newChildren.add(children.get(j)); } for (int j = toRemove + 1; j < children.size(); j++) { newChildren.add(children.get(j)); } } return new ListResult(parentModStamp, newChildren, parentId); }