Advertisement
ivana_andreevska

AV8 Reverse List

Aug 15th, 2022
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. package AV8;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collection;
  5. import java.util.List;
  6.  
  7. public class ReverseListTest {
  8.     public static <T> void reversePrint(Collection<T> collection) {
  9.         List<T> list = new ArrayList<>();
  10.         list.addAll(collection);
  11.  
  12.         for (int i = list.size() - 1; i >= 0; i--) {
  13.             System.out.println(list.get(i));
  14.         }
  15.     }
  16.  
  17.     public static void main(String[] args) {
  18.     List<Integer> ints=List.of(1,2,3,4,5,6,7,8,9,10);
  19.     reversePrint(ints);
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement