Click here to Skip to main content
15,888,077 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need help to Write a Java interface called Reversible which has a single method public void reverse(), where it reverses the elements in a list.

What I have tried:

I have tried
import java.util.ArrayList;

import java.util.Collections;


public class ReverseListOrder {

  
  public static void main(String[] args) {


    ArrayList arrayList = new ArrayList();

    arrayList.add("0");

    arrayList.add("1");

    arrayList.add("2");

    arrayList.add("3");
    arrayList.add("4");

 
   System.out.println("ArrayList elements : " + arrayList);

  
  Collections.reverse(arrayList);

    System.out.println("ArrayList elements after reversing order : " + arrayList);

}
}


but i dont think this is an 'interface'.
Posted
Updated 24-Oct-18 20:35pm

Very easy: create a new collection, take the elements of the old collection via count down into the new and assign the result.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900