@@ -124,6 +124,15 @@ public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneab
124124 return ArrayFactory ::newConcurrentStampedLockArray ;
125125 }
126126
127+ /**
128+ * Copy all elements from this array to a target array.
129+ *
130+ * @param target the target array.
131+ */
132+ default void copyTo (@ NotNull Array <? super E > target ) {
133+ target .addAll (this );
134+ }
135+
127136 /**
128137 * Adds all elements from the array to this array.
129138 *
@@ -418,8 +427,7 @@ default int lastIndexOf(@NotNull Object object) {
418427 }
419428
420429 /**
421- * Removes all of this target's elements that are also contained in the specified array (optional operation). After
422- * this call returns, this array will contain no elements in common with the specified array.
430+ * Removes all of this target's elements that are also contained in the specified array (optional operation).
423431 *
424432 * @param target array containing elements to be removed from this array.
425433 * @return true if this array changed as a result of the call.
@@ -432,15 +440,48 @@ default boolean removeAll(@NotNull Array<?> target) {
432440
433441 int count = 0 ;
434442
435- for (Object element : target .array ()) {
443+ for (var element : target .array ()) {
436444 if (element == null ) {
437445 break ;
438446 } else if (slowRemove (element )) {
439447 count ++;
440448 }
441449 }
442450
443- return count == target .size ();
451+ return count > 0 ;
452+ }
453+
454+ /**
455+ * Removes all of this target's elements that are also contained in the specified array (optional operation)
456+ * with reordering.
457+ *
458+ * @param target array containing elements to be removed from this array.
459+ * @return true if this array changed as a result of the call.
460+ */
461+ default boolean fastRemoveAll (@ NotNull Array <?> target ) {
462+
463+ if (target .isEmpty ()) {
464+ return false ;
465+ }
466+
467+ var count = 0 ;
468+ var array = array ();
469+
470+ for (int i = 0 , length = size (); i < length ; i ++) {
471+
472+ var element = array [i ];
473+
474+ if (!target .contains (element )) {
475+ continue ;
476+ }
477+
478+ fastRemove (i );
479+ i --;
480+ length --;
481+ count ++;
482+ }
483+
484+ return count > 0 ;
444485 }
445486
446487 @ Override
0 commit comments