Java Program to Add Elements in ArrayList and Print Them in Reverse Order

You are currently viewing Java Program to Add Elements in ArrayList and Print Them in Reverse Order

Java program to add elements in ArrayList and print them in reverse order

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 array list elements in reverse order
    for(int iLoop=arrList.size()-1; iLoop >= 0; iLoop--)
      System.out.println(arrList.get(iLoop));
   
  }
}

Output

Array List elements: 
500
400
300
200
100

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply