CopyOnArrayList replaceAll() method in Java with Examples Last Updated : 08 Jan, 2019 Comments Improve Suggest changes Like Article Like Report The java.util.concurrent.CopyOnArrayList.replaceAll() method in Java replaces each element of this list with the result of applying the operator to the element. Syntax: public void replaceAll(UnaryOperator operator) Parameters: This method accepts a mandatory parameter operator which is to be applied to each element. Return Type: This method has no return value. Below Programs illustrate the replaceAll() method of CopyOnArrayList in Java: Program 1: This program involves CopyOnArraylist replaceAll() method of String Type: Java // Java Program to illustrate CopyOnArrayList // replaceAll() method import java.util.concurrent.CopyOnWriteArrayList; import java.util.*; import java.util.function.UnaryOperator; public class GFG { public static void main(String[] args) { CopyOnWriteArrayList<String> ArrLis1 = new CopyOnWriteArrayList<String>(); // Add elements ArrLis1.add("White"); ArrLis1.add("Red"); ArrLis1.add("Blue"); ArrLis1.add("Green"); // print CopyOnWriteArrayList System.out.println("CopyOnWriteArrayList: " + ArrLis1); // check using function ArrLis1.replaceAll(new MyOperator()); // print CopyOnWriteArrayList System.out.println("After replacement CopyonWriteArrayList: " + ArrLis1); } } class MyOperator implements UnaryOperator<String> { public String apply(String t) { return t.replaceAll("Red", "White"); } } Output: CopyOnWriteArrayList: [White, Red, Blue, Green] After replacement CopyonWriteArrayList: [White, White, Blue, Green] Comment More infoAdvertise with us Next Article CopyOnArrayList replaceAll() method in Java with Examples K kanakasrijaathukuri Follow Improve Article Tags : Java Practice Tags : Java Similar Reads CopyOnWriteArrayList retainAll() method in Java with Examples The Java.util.concurrent.CopyOnArrayList.retainAll() method in Java is used to retain only the elements in the list that are contained in specific collection. Syntax: public boolean retainAll(Collection col) Parameters: This method accepts a mandatory parameter col which is of the type of collection 2 min read CopyOnWriteArraySet removeAll() method in Java with Examples The removeAll() method of CopyonWriteArraySet method removes all the elements of this CopyOnWriteArraySet that are present in the specified collection. That means elements which are common in both the collections are removed from this CopyOnWriteArraySet. Syntax: public boolean removeAll(Collection 2 min read CopyOnWriteArrayList remove() method in Java with Examples The remove()method of CopyOnArrayList in Javais used to remove the element in the list. Syntax: 1. public E remove(int index) 2. public boolean remove(Object o) 1. remove(int index) The remove(int index) method of CopyOnArrayList in Java is used to remove the element at the specified position in the 3 min read CopyOnWriteArraySet retainAll() method in Java with Example The retainAll() method of java.util.concurrent.CopyOnWriteArraySet class is used to retain from this set all of its elements that are contained in the specified collection. Syntax: public boolean retainAll(Collection c) Parameters: This method takes collection c as a parameter containing elements to 3 min read Collections replaceAll() Method in Java with Examples The replaceAll() method of java.util.Collections class is used to replace all occurrences of one specified value in a list with another. More formally, replaces with newVal each element e in the list such that oldVal == null ? e==null : oldVal.equals(e) Note: This method has no effect on the size of 3 min read Like