1 // ListVar.java
2 package newlocal;
3
4 import java.util.Iterator;
5 import java.util.function.Consumer;
6
7 /** 8 * ListVar legt eine Liste ganzer Zahlen an und gibt sie aus. 9 * Beispielprogramm zur Programmiertechnik 1, Teil 5. 10 * @author H.Drachenfels 11 * @version 9.12.2016 12 */
13 public final class ListVar {
14 private ListVar() { }
15
16 /** 17 * main ist der Startpunkt des Programms. 18 * @param args wird nicht verwendet. 19 */
20 public static void main(String[] args) {
21 //------------------------------------------------- Liste anlegen
22 IntList anIntList = new IntList()
23 .insert(3814)
24 .insert(3635)
25 .insert(3442)
26 .insert(3421);
27
28 //------------------------------------------------ Liste ausgeben
29 System.out.println("Java 5 style iteration:");
30 for (int n : anIntList) {
31 System.out.println(n);
32 }
33
34 System.out.println("Java 5 style iteration explicitly:");
35 Iterator<Integer> i = anIntList.iterator();
36 while (i.hasNext()) {
37 int n = i.next();
38 System.out.println(n);
39 }
40
41 System.out.println("Java 8 style iteration:");
42 anIntList.forEach(System.out::println);
43
44 System.out.println("Java 8 style iteration explicitly:");
45 anIntList.forEach(
46 new Consumer<Integer>() {
47 @Override
48 public void accept(Integer n) {
49 System.out.println(n);
50 }
51 }
52 );
53 }
54 }
55