public
int size()
Returns
the number of elements in this list.
import java.util.*; class ArrayListSize{ public static void main(String args[]){ ArrayList<Integer> myList; myList = new ArrayList<> (); /* Add Elements to myList */ myList.add(10); myList.add(20); myList.add(30); myList.add(40); System.out.println("Elements in myList are"); System.out.println(myList); System.out.print("Number Of Elements in myList are "); System.out.println(myList.size()); } }
Output
Elements in myList are [10, 20, 30, 40] Number Of Elements in myList are 4
No comments:
Post a Comment