package com.javatraineronline;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ReverseList {
public static void main(String[] args) {
// Declaring the ArrayList 
List<String> list = new ArrayList<String>();
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
list.add("Five");
// Printing the before reverse
System.out.println("Before : "+list);
Collections.reverse(list); // 'Collections' is a class 'reverse' is predefined method. 
//Printing the after reverse
System.out.println("After : "+list);
}
}

[su_box title=”Output for ReverseList.java”]
Before : [One, Two, Three, Four, Five]

After : [Five, Four, Three, Two, One]
[/su_box]

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *