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]
No comments:
Post a Comment