ArrayList Creation

In this chapter you will learn:

  1. What are constructors for ArrayList

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;
/*  java2s .  co m*/
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:

  1. How to add elements to an ArrayList
Home » Java Tutorial » List

List

    List interface
    List add/insert elements
    List clear/remove elements
    List search
    List element get and set
    List and its Iterator
    List size, empty
    List conversion, to array
    List to sublist
    List comparison
    List filling
    List reversing
    List rotating and shuffling
    List sorting
    List element swap
    List element replacing
    List copy
    List binary search

ArrayList

    ArrayList
    ArrayList Creation
    ArrayList add/insert
    ArrayList get/set element
    ArrayList clear/remove
    ArrayList search
    ArrayList copy and shallow copy
    ArrayList size, trim to size and capacity
    ArrayList to array

LinkedList

    LinkedList class
    LinkedList creation
    LinkedList add/insert elements
    LinkedList get elements
    LinkedList search
    LinkeList replace/set elements
    LinkedList remove element
    LinkedList copy
    LinkedList iterator
    LinkedList peek element
    LinkedList pop/push element
    LinkedList conversion

List Utilities

    List filling
    List reversing
    List rotating and shuffling
    List sorting
    List element swap
    List element replacing
    List copy
    List binary search