How to use List?

In Java, we must import java.util.List package in order to use List.


\begin{lstlisting}
// ArrayList implementation of List
List<String> list1 = new ...
...implementation of List
List<String> list2 = new LinkedList<>();
\end{lstlisting}

Here, we have created objects list1 and list2 of classes ArrayList and LinkedList. These objects can use the functionalities of the List interface.