Question: THIS IS A JAVA PROGRAM THAT NEEDS TO BE WRITTEN Write a recursive method void reverse(ArrayList obj) that reverses an ArrayList of any type of

THIS IS A JAVA PROGRAM THAT NEEDS TO BE WRITTEN

Write a recursive method void reverse(ArrayList obj) that reverses an ArrayList of any type of object. For example, if an ArrayList held 4 strings: "hi", "hello", "howdy", and "greetings" the order would become "greetings", "howdy", "hello", and "hi". Implement a recursive solution by removing the first object, reversing the ArrayList consisting of the remaining Objects, and combining the two. Use the following class ArrayListReverser to write and test your program.

import java.awt.Rectangle; import java.util.ArrayList; public class ArrayListReverser { public static void main(String[] args) { ArrayList myList = new ArrayList(); myList.add(new Rectangle(1,1)); myList.add(new Rectangle(2,2)); myList.add(new Rectangle(3,3)); myList.add(new Rectangle(4,4)); for (Object o:myList) System.out.println(o); reverse(myList); System.out.println(" The order should now be reversed:"); for (Object o:myList) System.out.println(o); } //your method here }                                             
                    

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!