Using remove() Method

To remove an element from an array list, we can use the remove() method. For example,


\begin{lstlisting}
import java.util.ArrayList;
\par
class Main {
public static ...
...imals);
System. out.println(''Removed Element: '' + str);
}
}
\end{lstlisting}

Output


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