Java List.size()

Syntax

List.size() has the following syntax.

int size()

Example

In the following code shows how to use List.size() method.


import java.util.ArrayList;
import java.util.List;
/* ww w.j a v a  2  s  . c om*/
public class Main {
  public static void main(String[] args) {
    List list = new ArrayList();

    list.add("1");
    list.add("2");
    list.add("3");
 
    list.add("java2s.com");

    System.out.println("List has:" + list.size());
  }
}

The code above generates the following result.