Showing posts with label how to get size of arraylist. Show all posts
Showing posts with label how to get size of arraylist. Show all posts

Sunday, 10 May 2015

How to count number of element in ArrayList

Size() Method return number of element in the arraylist.

import java.util.ArrayList;

public class CountElement {

    public static void main(String[] args) {

        ArrayList<String> arr = new ArrayList<String>();

        // add element in arraylist

        arr.add("c");
        arr.add("php");
        arr.add("html");
        arr.add("java");
        arr.add("delhi");
        arr.add("INDIA");

        // print arraylist

        System.out.println("arrayList is = " + arr);

        /*
         * Returns the number of elements in this list.
         */

        System.out.println(" size = "+arr.size());

    }

}

Output:

arrayList is = [c, php, html, java, delhi, INDIA]

 size = 6


Related Posts: 

 


Storing Java Object In ArrayList