Solved programming problem

Find Array List Size in Java.

Source code

package inputoutput;

import java.util.Scanner;

import java.util.ArrayList; ///import array list

public class InputOutput

{

 

    public static void main(String[] args)

    {

        Scanner s = new Scanner(System.in);

        ArrayList<Integer>Array = new ArrayList<Integer>();

       

        System.out.println("Enter Array Size: ");

        int n = s.nextInt();

       

        System.out.println("Enter Array Element: ");

        for(int i =0;i<n;i++)

        {

            int temp = s.nextInt();

            Array.add(temp);      

        }

       

        int size = Array.size(); /// find array size

       

        System.out.println("Your Array Size: "+size);

         

    }

   

}

Output

Enter array size:

5

Enter array elements:

1 3 5 7 9

Your array size:5

Join the discussion

Add your comment