Write a Java program to reverse elements in a array list

Write a Java program to reverse elements in a array list


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  1. import java.util.*;
  2. public class Javacollectionexcercise {
  3. public static void main(String[] args) {
  4.  
  5. List<String> Stringslist = new ArrayList<String>();
  6. Stringslist.add("Audi");
  7. Stringslist.add("BMW");
  8. Stringslist.add("Bugatti");
  9. Stringslist.add("Ford");
  10. Stringslist.add("Honda");
  11. Stringslist.add("Hyundai");
  12.  
  13. System.out.println("List before reversing :\n" + Stringslist);
  14. Collections.reverse(Stringslist);
  15. System.out.println("List after reversing :\n" + Stringslist);
  16. }
  17. }

Result

java techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.