Add elements of an array list to another array list

To add all the elements of an array list to a new array list, we use the addAll() method. For example,


\begin{lstlisting}
import java.util.ArrayList;
\par
class Main {
public static ...
...ll(mammals);
System.out.println(''Animals: '' + animals);
}
}
\end{lstlisting}

Output


\begin{lstlisting}
Mammals: [Dog, Cat, Horse]
Animals: [Crocodile, Dog, Cat, Horse]
\end{lstlisting}