xxxxxxxxxx
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
// Create a new list using ArrayList
List<String> myList = new ArrayList<>();
// Add elements to the list
myList.add("First element");
myList.add("Second element");
myList.add("Third element");
// Access and print elements of the list
for (String element : myList) {
System.out.println(element);
}
}
}
xxxxxxxxxx
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
class scratch{
public static void main(String[] args) {
List<Integer> aList = new ArrayList<>();
List<Integer> lList = new LinkedList<>();
}
}
xxxxxxxxxx
// ArrayList implementation of List
List<String> list1 = new ArrayList<>();
// LinkedList implementation of List
List<String> list2 = new LinkedList<>();
xxxxxxxxxx
List myList = new ArrayList();
// Or with Java 7 or ealier generic
List<MyType> myList = new ArrayList<>();
// Or
List<MyType> myList = new ArrayList<MyType>();
xxxxxxxxxx
List<Integer> list=new ArrayList<Integer>();
List<Integer> llist=new LinkedList<Integer>();
List<Integer> stack=new Stack<Integer>();