### Question:
DuplicateOnWriteSimpleCollection implements SimpleCollection<E> { public DuplicateOnWriteSimpleCollection<E> replace(E newElement, E oldElement) { final Object[] newElements = new Object[elements.length]; boolean removed = false; for (int i = 0; i < elements.length; i++) { if (!removed && elements[i].equals(oldElement)) { newElements[i] = newElement; removed = true; } else { newElements[i] = elements[i]; } } if (removed) { return new DuplicateOnWriteSimpleCollection<>(newElements); } else { return this; } } private  DuplicateOnWriteSimpleCollection(); private  DuplicateOnWriteSimpleCollection(Object[] collection); @Override int size(); @Override boolean isEmpty(); @Override Iterator<E> iterator(); @Override Iterator<E> structuralIterator(); DuplicateOnWriteSimpleCollection<E> add(E element); DuplicateOnWriteSimpleCollection<E> remove(E element); DuplicateOnWriteSimpleCollection<E> replace(E newElement, E oldElement); static DuplicateOnWriteSimpleCollection<E> create(); static DuplicateOnWriteSimpleCollection<E> create(E[] array);  }### Answer:
@Test public void replace() { final DuplicateOnWriteSimpleCollection<CharSequence> collection = DuplicateOnWriteSimpleCollection.create(new String[] {"Who", "is", "a", "good", "boy?"}); final DuplicateOnWriteSimpleCollection<CharSequence> modifiedCollection = collection.replace(new StringBuffer("bad"), "good"); for (final CharSequence element : modifiedCollection) { assertNotEquals("good", element); } }