• Source
    1. /* package whatever; // don't place package name! */
    2.  
    3. import java.util.*;
    4. import java.lang.*;
    5. import java.io.*;
    6.  
    7. /* Name of the class has to be "Main" only if the class is public. */
    8. class Ideone
    9. {
    10. public static void main (String[] args) throws java.lang.Exception
    11. {
    12. List<Integer> prueba = new ArrayList<Integer>(6);
    13.  
    14. prueba.add(1);
    15. prueba.add(2);
    16. prueba.add(3);
    17. prueba.add(4);
    18. prueba.add(5);
    19. prueba.add(6);
    20.  
    21. Ideone.toTraverse(prueba);
    22. }
    23.  
    24. public static <E> void toTraverse(List<E> lista) {
    25.  
    26. Iterator<E> it = lista.iterator();
    27. while(it.hasNext()) {
    28. E obj = it.next();
    29. System.out.println(obj);
    30. }
    31. }
    32.  
    33. }