Skip to main content

Posts

Showing posts with the label What is the Simplest Way to Reverse an ArrayList?

What is the Simplest Way to Reverse an ArrayList?

 What is the Simplest Way to Reverse an ArrayList? Do Check My Video On Utility Classes: Reverse the element of the list mehtod : public static void reverse(List l) Example:    import java.util.ArrayList; import java.util.Collections; public class Test{     public static void main(String[] args) {         ArrayList l = new ArrayList();         l.add(3);         l.add(333);         l.add(23);         l.add(33);         l.add(43);         l.add(36);         System.out.println(l);//[3, 333, 23, 33, 43, 36]         Collections.reverse(l);         System.out.println(l);//[36, 43, 33, 23, 333, 3]     } } o/p: [3, 333, 23, 33, 43, 36] [36, 43, 33, 23, 333,3]