2016-09-29

Java 8: Find First Match

Oh, how I love chainable methods, especially over a stream...

// Return first match in this List, or null.
return contents.stream().filter(c -> c.name.equals(fieldName)).findFirst().orElse(null);

<3 lambda <3

2016-09-27

Java 8: Not So Poor Man's Timing

import java.time.Duration;
import java.time.Instant;

// ...

Instant start = Instant.now();
// Timed operations come here
Instant stop = Instant.now();
System.out.println("Task ran for: " + Duration.between(start, stop));

I love it.