Q:

Java program to create an ArrayList, add elements and print

belongs to collection: Java ArrayList Programs

0

Java program to create an ArrayList, add elements and print

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program

import java.util.ArrayList;
 
public class ExArrayList {
 
  public static void main(String[] args) {
    ////Creating object of ArrayList
    ArrayList arrList = new ArrayList();
   
    //adding data to the list
    arrList.add("100");
    arrList.add("200");
    arrList.add("300");
    arrList.add("400");
    arrList.add("500");
   
    System.out.println("Array List elements: ");
    //display elements of ArrayList
    for(int iLoop=0; iLoop < arrList.size(); iLoop++)
      System.out.println(arrList.get(iLoop));
   
  }
}

Output

Array List elements: 
100
200
300
400
500

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java program to add element at specific index in A... >>