java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to know the size of ArrayList?

package com.javacoderanch.example.util;

import java.util.ArrayList;
import java.util.List;

public class ArrayListSize
{
    public static void main(String[] args)
    {
        List list = new ArrayList();
        list.add("Item 1");
        list.add("Item 2");

        int size = list.size();
        System.out.println("size = " + size);
    }
}