Skip to content

Instantly share code, notes, and snippets.

View avdyk's full-sized avatar

Arnaud Vandyck avdyk

View GitHub Profile
@avdyk
avdyk / date-time-api-java-11.jshell
Last active April 8, 2019 09:04
Exemples d'utilisation de l'API Date&Time (jshell java 11)
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();
@avdyk
avdyk / var-stream-filter-forEach.jshell
Created April 4, 2019 14:03
Java 11 exemple du type "var"; fabrique de liste, stream, filtre, tri, forEach
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
*/