Print a CopyOnWriteArrayList

Report a typo

You have the following task:

  • add elementToAdd to the given CopyOnWriteArrayList

  • print its elements using an iterator as in the example below.

An example of the output:

first second third last

Write a program in Java 17
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Iterator;

class PrintElementsClass {

public static void printElements(CopyOnWriteArrayList<String> onWriteArrayList, String elementToAdd) {
// write your code here:

}
}
___

Create a free account to access the full topic