Reverse order of all elements of ArrayList

Reverse order of all elements of ArrayList

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

public class ReverseAllelement {

public static void main(String[] args) {
ArrayList<String> arr = new ArrayList<String>();
// add element in arraylist
arr.add(“c”);
arr.add(“php”);
arr.add(“html”);
arr.add(“java”);
// print arraylist
System.out.println(“Before Reverse ArrayList Is = ” + arr);

Collections.reverse(arr);

System.out.println(“After Reverse ArrayList Is = ” + arr);
}

}

Output:

Before Reverse ArrayList Is = [c, php, html, java]

After Reverse ArrayList Is = [java, html, php, c]

 

Related Posts: 

 

Storing Java Object In ArrayList

Leave a Reply

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

69 − = 66