This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.*; // exemples basés sur http://blog.paumard.org/2014/04/22/50-nouvelles-choses-que-lon-peut-faire-avec-java-8/ | |
| var start = Instant.now(); // un instant est un point de la ligne du temps | |
| var end = Instant.now(); | |
| Duration elapsed = Duration.between(start, end); // une durée | |
| long millis = elapsed.toMillis(); | |
| elapsed.plusSeconds(2L); // calcul sur les durées | |
| var now = LocalDate.now(); // une date empirique | |
| var shakespearDoB = LocalDate.of(1564, Month.APRIL, 23); | |
| Period p = shakespearDoB.until(now); // une durée entre LocalDate | |
| int years = p.getYears(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var nameList = List.of("Thibaut", "Olivier", "Jean-Baptiste", "Arnaud"); | |
| nameList.stream().filter(n -> n.contains("a")).sorted().forEach(n -> System.out.println(n)); | |
| /* output: | |
| Arnaud | |
| Jean-Baptiste | |
| Thibaut | |
| */ |