Implement a method called reverse public static void reverse

Implement a method called reverse (\"public static void reverse(LinkedList strings)\") that takes in a LinkedList of strings and reverses each entry in the linked list. (No main is required for this question; the output below comes from us testing the method from another class.)

Solution

Method Implementation:

public static void reverse(LinkedList strings){

       //calculate length of the LinkedList
        int length=strings.size();   

        //Traverse through the Linked list
        for(int i=0;i<length;i++){
           String s=strings.get(i).toString();
            String r=new StringBuilder(s).reverse().toString();
            strings.remove(i);
            strings.add(i,r);
        }
    }

Note:

Explanation:

Tested by calling \'reverse\' method from a main method as well.

Implement a method called reverse (\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site