Method/constructor references are more compact and readable than using lambdas, and are therefore preferred.
Note that this rule is automatically disabled when the project's java.source.version is lower than 8.
Listlist = new ArrayList (); list.add(0); list.add(1); list.add(2); list.forEach(n -> { System.out.println(n); });
Listlist = new ArrayList (); list.add(0); list.add(1); list.add(2); list.forEach(System.out::println);