Pages

Monday, August 18, 2025

Reverse of ArrayList in Java

import java.util.ArrayList;

public class Classroom {

    public static void main(String[] args) {
       ArrayList<Integer> list = new ArrayList<>();
       list.add(1);
       list.add(2);
       list.add(3);
       list.add(4);
       list.add(5);

       // Reverse Print - O(n)
       for(int i=list.size()-1; i>= 0; i--) {
        System.out.println(list.get(i));
       }
    }
}

No comments:

Post a Comment

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...