Using removeAll() method

To remove all elements from an array list, we use the removeAll() method. For example,


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

Output


\begin{lstlisting}
Initial ArrayList: [Dog, Cat, Horse]
Final ArrayList: []
\end{lstlisting}