Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.
List<String> nomsEnA = noms.stream()
.filter(nom -> nom.startsWith("A"))
.collect(Collectors.toList());
ArrayList<Integer> nombres = new ArrayList<>();
nombres.add(5);
nombres.forEach( (n) -> { System.out.println(n); } );
List<String> noms = Arrays.asList("Alice", "Bob", "Anna");
noms.stream()
.filter(nom -> nom.startsWith("A"))
.forEach(System.out::println);
List<Integer> nombres = Arrays.asList(1, 2, 3, 4, 5);
int somme = nombres.stream()
.reduce(0, (a, b) -> a + b);
List<Integer> longueurs = noms.stream()
.map(String::length)
.collect(Collectors.toList());
noms.stream()
.sorted()
.forEach(System.out::println);
Optional<String> premierNomEnC = noms.stream()
.filter(n -> n.startsWith("C"))
.findFirst();
premierNomEnC.ifPresent(System.out::println);