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]
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet