1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import java.util.*; public class Main { public static void main(String[] args) throws Exception { var sub = new Sub(); sub.run(); } } class Sub { public void run() { var list = getList(); p(list); var iterator = list.iterator(); while (iterator.hasNext()) { var next = iterator.next(); p(next); } } public <T> void p(T a) { System.out.println(a); } public void p() { System.out.println(); } public List getList() { var n = 5; List<Integer> list = new ArrayList<>(); for (var i = 0; i < n; i++) { list.add(i); } return list; } } |
1 2 3 4 5 6 |
[0, 1, 2, 3, 4] 0 1 2 3 4 |