Java ArrayList size Example
ArrayList class size method example. This example shows you how to use size method.
ArrayList class size method example.public int size() Returns the number of elements in this list.
Here is the code
/**
* @ # Size.java
* A class repersenting use to Size method of ArrayList class in java.util package
* version 14 May 2008
* author Rose India
*/
import java.util.*;
public class Size {
public static void main(String args[]) {
List arrlist = new ArrayList();
int i = 0;
String str = "Rose";
//Add the specified element to the end of this list.
arrlist.add(i);
System.out.println("arrlist " + arrlist +
"\nSize of the arrlist = " + arrlist.size());
arrlist.add(str);
System.out.println("\narrlist " +arrlist+
"\nSize of the arrlist = " + arrlist.size());
arrlist.add("India");
System.out.println("\narrlist " +arrlist +
"\nSize of the arrlist = " + arrlist.size());
}
} |
Output
arrlist [0]
Size of the arrlist = 1
arrlist [0, Rose]
Size of the arrlist = 2
arrlist [0, Rose, India]
Size of the arrlist = 3 |
|