This documentation is archived and is not being maintained.

ArrayList.size Method

Visual Studio 2005

Provides the number of elements in a ArrayList object.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public int size();

The number of elements in a ArrayList object.

The following example prints the size of an ArrayList object.

// arraylist_size.jsl

import java.util.*;

public class Program
{
    public static void main(String[] args)
    {
        // Create an ArrayList containing elements 1, 2, 3.
        ArrayList initialArray = new ArrayList();
        initialArray.add(new Integer(1));
        initialArray.add(new Integer(2));
        initialArray.add(new Integer(3));

        // Determine the size of the ArrayList.
        int size = initialArray.size();
        System.out.println("ArrayList contains " + size +
            " elements.");
    }
}

/*
Output:
ArrayList contains 3 elements.
*/
Show: