boolean (E e) { Object[] elements; Object[] newElements; do { // Copy while checking if already present. // This wins in the most common case where it is not present elements = get(); int len = elements.length; newElements = new Object[len + 1]; for (int i = 0; i < len; ++i) { if (Objects.equals(e, elements[i])) { return false; // exit, throwing away copy } newElements[i] = elements[i]; } newElements[len] = e; } while (!replaceArray(elements, newElements)); return true; }