Add elements in CopyOnWriteArrayList

In this post we will see how to add elements in CopyOnWriteArrayList using below 2 methods
1. boolean add(E e)
Appends the specified element to the end of this list.

2. void add(int index, E element)
Inserts the specified element at the specified position in this list.

In the below code we will do the following
1. Create a copyOnWriteArrayList object
2. Add 4 elements using add(E e) method
3. Print the added elements
4. Add 2 more elements at index 2 and 3 using add(int index, E element)
5. Print the entire object

Code for Add elements in CopyOnWriteArrayList

Output

Add elements in CopyOnWriteArrayList

Reference

1. Add methods in CopyOnWriteArrayList

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn