Thursday, 31 July 2014

Write a Program in Java which add integers in ArrayList

Structure of the Problem Requirements 

In this problem we will learn how to store any value in ArrayList in Java. ArrayList is same like Arrays in programming but a little bit mature then Arrays :). ArrayList exist in java.util.ArrayList class . we declare an object of this class and then pass the different value to it to store them . This is very simple example which will be more clear when you practice it and see the output at the end of the program.

Source Code 

package com.ancodingpoints.www;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Array_List {

 public static void main (String [] args )
 {
     int size = 0;
     Scanner input = new Scanner (System.in);
     ArrayList <Integer> num = new ArrayList <Integer> ();
     for (int i= 0; i<5;i++)
     {
         System.out.println(" Enter Your Number ");
         num.add(input.nextInt());
     }
     System.out.println(" Your Array list contain : ");
     System.out.println(num);
     
     }
     }
     
  

Output of the Program


Java Array List
Java Array List






Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment