Write a java program to accept 'n' integers from the user and store them in an ArrayList Collection.Display the elements of an ArrayList in Reverse order |EasyCoding45

Write a java program to accept 'n' integers from the user and store them in an ArrayList Collection. Display the elements of an ArrayList in Reverse order.


In this Tutorial we are going to learn how we can Write a java program to accept 'n' integers from the user and store them in an ArrayList Collection.Display the elements of an ArrayList in Reverse order.


Program :-


import java.util.*;

class array

{

public static void main(String a[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter Limit of ArrayList :");

int n=sc.nextInt();

ArrayList alist=new ArrayList();

System.out.println("Enter Elements of ArrayList :");

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

{

String elmt=sc.next();

alist.add(elmt);

}

System.out.println("Original ArrayList is :"+alist);

Collections.reverse(alist);

System.out.println("Reverse of a ArrayList is :"+alist);

}

}


Output :-




Comments