fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Reverse
  6. {
  7. static <T> void reverse(List<T> x){
  8. int n = x.size();
  9. for(int i=0;i<n/2;i++){
  10. T tmp = x.get(i);
  11. x.set(i, x.get(n-i-1));
  12. x.set(n-i-1, tmp);
  13. }
  14. }
  15.  
  16. public static void main (String[] args)
  17. {
  18. List<String> list = new ArrayList<String>();
  19. list.add("one");
  20. list.add("two");
  21. list.add("three");
  22. list.add("four");
  23. list.add("five");
  24.  
  25. reverse(list);
  26. for(String s:list)
  27. System.out.println(s);
  28. }
  29. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
five
four
three
two
one