CopyOnWriteArrayList toString() method in Java Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The toString() method of CopyOnWriteArrayList returns the string representation of the list. Syntax: public String toString() Parameters: The function does not accepts any parameter. Return Value: The function returns the string representation of the list. Below programs illustrate the above function: Program 1: Java // Java Program to illustrate the CopyOnWriteArrayList // toString() method in Java import java.util.concurrent.CopyOnWriteArrayList; import java.util.*; public class GFG { public static void main(String[] args) { // create object of CopyOnWriteArrayList CopyOnWriteArrayList<Integer> ArrLis = new CopyOnWriteArrayList<Integer>(); // Add elements ArrLis.add(32); ArrLis.add(67); ArrLis.add(98); ArrLis.add(100); // print CopyOnWriteArrayList System.out.println("CopyOnWriteArrayList: " + ArrLis); System.out.println("ArrLis converted to string: " + ArrLis.toString()); } } Output: CopyOnWriteArrayList: [32, 67, 98, 100] ArrLis converted to string: [32, 67, 98, 100] Program 2: Java // Java Program to illustrate the CopyOnWriteArrayList // toString()() method in Java import java.util.concurrent.CopyOnWriteArrayList; import java.util.*; public class GFG { public static void main(String[] args) { // create object of CopyOnWriteArrayList CopyOnWriteArrayList<String> ArrLis = new CopyOnWriteArrayList<String>(); // Add elements ArrLis.add("gopal"); ArrLis.add("gfg"); ArrLis.add("jgec"); ArrLis.add("sudo"); // print CopyOnWriteArrayList System.out.println("CopyOnWriteArrayList: " + ArrLis); System.out.println("ArrLis converted to string: " + ArrLis.toString()); } } Output: CopyOnWriteArrayList: [gopal, gfg, jgec, sudo] ArrLis converted to string: [gopal, gfg, jgec, sudo] Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CopyOnWriteArrayList.html#toString-- Comment More infoAdvertise with us Next Article CopyOnWriteArrayList spliterator() method in Java G gopaldave Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-CopyOnWriteArrayList +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads CopyOnWriteArrayList toArray() method in Java The toArray() method of CopyOnWriteArrayList is used to return an array containing all the elements in CopyOnWriteArrayList in the correct order. Syntax: public Object[] toArray() or public <T> T[] toArray(T[] a) Parameters: This method either accepts no parameters or it takes an array T[] a a 2 min read CopyOnWriteArrayList size() method in Java The size() method of CopyOnWriteArrayList returns the size of the list. It returns the number of elements in the list. Syntax: public int size() Parameters: The function does not accepts any parameter. Return Value: The function returns the size of the list. Below programs illustrate the above funct 1 min read CopyOnWriteArraySet size() method in Java The size() method of CopyOnWriteArraySet returns the size of the Set. It returns the number of elements in the current Set. Syntax: public int size() Return Value: The function returns the number of elements in the current Set. Below programs illustrate the above function: Program 1: Java // Java Pr 2 min read CopyOnWriteArrayList spliterator() method in Java The spliterator() method of CopyOnWriteArrayList returns an spliterator over the elements in this list in proper sequence. There is no need of synchronization while operating on the spliterator. Syntax: public Spliterator spliterator() Parameters: The function does not accept any parameters. Return 2 min read CopyOnWriteArrayList get() method in Java The get(index) method of CopyOnWriteArrayList returns the element at the specified index. Syntax: public E get(int index) Parameters: The function accepts a mandatory parameter index which specifies the index of the element to be returned. Return Value: The function returns the element at the given 2 min read CopyOnWriteArrayList add() method in Java The add(E e) method of CopyOnWriteArrayList inserts the element passed in the parameter to the end of the List or at a specified index in the list. The function returns true on addition of new element to the list. Syntax: public boolean add(E e) or public void add(int index, E element) Parameters: T 2 min read Like