1import java.util.ArrayList;
2public class ArrayListSizeMethodExample
3{
4 public static void main(String[] args)
5 {
6 ArrayList<Integer> al = new ArrayList<Integer>();
7 int s = al.size();
8 System.out.println("size of ArrayList: " + s);
9 al.add(25);
10 al.add(64);
11 al.add(73);
12 s = al.size();
13 System.out.println("size of ArrayList after adding elements: " + s);
14 al.clear();
15 s = al.size();
16 System.out.println("size of ArrayList after clearing elements: " + s);
17 }
18}
1import java.util.ArrayList;
2public class ArrayListSizeMethodExample
3{
4 public static void main(String[] args)
5 {
6 ArrayList<String> al = new ArrayList<String>();
7 int s = al.size();
8 System.out.println("size of ArrayList: " + s);
9 al.add("red");
10 al.add("blue");
11 al.add("green");
12 s = al.size();
13 System.out.println("size of ArrayList after adding elements: " + s);
14 al.clear();
15 s = al.size();
16 System.out.println("size of ArrayList after clearing elements: " + s);
17 }
18}