adsense


Showing posts with label JAVA EXAMPLES REVERSING AN ARRAY LIST. Show all posts
Showing posts with label JAVA EXAMPLES REVERSING AN ARRAY LIST. Show all posts

Saturday, 24 October 2015

JAVA EXAMPLES REVERSING AN ARRAY LIST PAGE 47

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES REVERSING AN ARRAY LIST



Java Examples - Reversing an array list


Problem Description:
How to reverse an array list ?
Solution:
Following example reverses an array list by using Collections.reverse(ArrayList)method.
import java.util.ArrayList;
import java.util.Collections;

public class Main {
   public static void main(String[] args) {
      ArrayList arrayList = new ArrayList();
      arrayList.add("A");
      arrayList.add("B");
      arrayList.add("C");
      arrayList.add("D");
      arrayList.add("E");
      System.out.println("Before Reverse Order: " + arrayList);
      Collections.reverse(arrayList);
      System.out.println("After Reverse Order: " + arrayList);
   }
}
Result:
The above code sample will produce the following result.
Before Reverse Order: [A, B, C, D, E]
After Reverse Order: [E, D, C, B, A]