ArrayList is same like Arrays but a little bit mature then Arrays :). ArrayList exist in java.util.ArrayList class. We can declare an object of this class and then pass the different value to it to store. 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); } }
0 comments:
Post a Comment