How to reverse the order of all the elements of ArrayList in Java

1 Answer

0 votes
package javaapplication1;

import java.util.ArrayList;
import java.util.Collections;

public class JavaApplication1 {

    public static void main(String[] args) {

        ArrayList arrList = new ArrayList();

        arrList.add("aaa");
        arrList.add("bbb");
        arrList.add("ccc");
        arrList.add("ddd");
        arrList.add("eee");
        arrList.add("fff");
        arrList.add("ggg");
   
        System.out.println(arrList);
        
        System.out.println();
   
        Collections.reverse(arrList);
   
        System.out.println(arrList);
  }
}
  
/*
run:

[aaa, bbb, ccc, ddd, eee, fff, ggg]

[ggg, fff, eee, ddd, ccc, bbb, aaa]

*/

 



answered Sep 26, 2016 by avibootz

Related questions

1 answer 208 views
1 answer 209 views
1 answer 186 views
1 answer 247 views
1 answer 206 views
...