Java Reference
In-Depth Information
LocalDate myDate = LocalDate.now();
LocalTime myTime = LocalTime.now();
LocalDate datePlusDays = myDate.plusDays(15);
System.out.println("Today Plus 15 Days: " + datePlusDays);
LocalDate datePlusWeeks = myDate.plusWeeks(8);
System.out.println("Today Plus 8 weeks: "
+ datePlusWeeks);
LocalTime timePlusHours = myTime.plusHours(5);
LocalTime timeMinusMin = myTime.minusMinutes(30);
System.out.println("Time Plus 5 Hours: " + timePlusHours);
System.out.println("Time Minus 30 Minutes: "
+ timeMinusMin);
How It Works
The Date-Time API makes it easy to perform calculations on dates and times. The
LocalDate and LocalTime objects have calculation methods built right in, so
there is no more worrying about converting to different types of objects in order to per-
form calculations. The Date-Time API also allows easy access to the current date or
time by enabling you to invoke the now() method on either of those objects.
Streams API
Collections play an integral role in many Java applications. The release of Java 8 intro-
duced the Streams API, which changes the way that collections of data can be used,
making solutions more productive and maintainable. The Streams API allows you to
traverse over a collection of elements and perform aggregate operations, pipeline two
or more operations, perform parallel execution, and more. This section provides a
glimpse of the Streams API. To learn more, refer to Recipe 7-8.
2-8. Iterating Over a Collection of Data
Search WWH ::




Custom Search