Write a Java program to reverse elements in a array list
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..
import java.util.*; public class Javacollectionexcercise { public static void main(String[] args) { List<String> Stringslist = new ArrayList<String>(); Stringslist.add("Audi"); Stringslist.add("BMW"); Stringslist.add("Bugatti"); Stringslist.add("Ford"); Stringslist.add("Honda"); Stringslist.add("Hyundai"); System.out.println("List before reversing :\n" + Stringslist); Collections.reverse(Stringslist); System.out.println("List after reversing :\n" + Stringslist); } }
Result:
[Audi, BMW, Bugatti, Ford, Honda, Hyundai]
List after reversing :
[Hyundai, Honda, Ford, Bugatti, BMW, Audi]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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..
Result:
[Audi, BMW, Bugatti, Ford, Honda, Hyundai]
List after reversing :
[Hyundai, Honda, Ford, Bugatti, BMW, Audi]
need an explanation for this answer? contact us directly to get an explanation for this answer