ArrayList Creation
In this chapter you will learn:
ArrayList Constructors
ArrayList
has the constructors shown here:
ArrayList( )
builds an empty array list.ArrayList(Collection<? extends E> c)
builds an array list that is initialized with the elements of the collection c.ArrayList(int capacity)
builds an array list that has the specified initial capacity.
The capacity is the size of the underlying array that is used to store the elements. The capacity grows automatically as elements are added to an array list.
import java.util.ArrayList;
// j a v a2s.c om
public class Main {
public static void main(String args[]) {
ArrayList<String> al = new ArrayList<String>();
System.out.println(al);
}
}
The code above creates an ArrayList
with its default constructor.
After creation the ArrayList
is empty.
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Collections