Compare Two LocalDate Instances in Java

Learn to compare two LocalDate instances to find out which date represents an older date in comparison to second date. LocalDate class is part of java.time package added in Java 8.

Using cURL on Windows PowerShell

Learn to execute the cURL commands from Windows. Beginning in Insider Build 17063, Tar and curl are available from the command-line for all SKUs of Windows.

Guide to AtomicInteger in Java

The AtomicInteger class protects an underlying int value by providing methods that perform atomic operations on the value. It shall not be used as a replacement for an Integer class.

How to Format LocalDate in Java

Java examples to format LocalDate to String using inbuilt and custom patterns using FormatType and format(formatter) API.

Java Check Leap Year Examples

Java programs to find if a given year is a leap year using new Java 8 APIs (LocalDate and Year), legacy Java 7 GregorianCalendar, and custom code.

Compare Two ZonedDateTime Instances

Learn to compare two instances of ZonedDateTime either in the same timezone or in different timezones in Java 8. 2. Comparing at Same Instant As we know an instance of ZonedDateTime is a point in the universal timeline with an offset. So to compare two such instances, logically, both instances …

Convert between LocalDate and ZonedDateTime

Learn to convert from LocalDate to ZonedDateTime and from ZonedDateTime to LocalDate in Java 8. As we know, LocalDate represents a calendar date without the time and the zone information. ZonedDateTime instance contains all three information i.e. date, time and zone. ZonedDateTime = LocalDate + time + timezone 1. LocalDate …

Parse String to ZonedDateTime in Java

Java 8 ZonedDateTime class represents an instant in the universal timeline with the timezone information. In this tutorial, we will learn to parse a string to ZonedDateTime object using its parse() method. 1. Parsing a Date Time with ZonedDateTime.parse() Java program to convert a given string into ZonedDateTime instance. After …

Convert String to LocalDate in Java

Java LocalDate class represents a calendar date without time (hour/minute/seconds) and timezone information. Learn to convert a string to LocalDate object in Java.

Java ZonedDateTime

Learn about the ZonedDateTime class in Java, how to create its instances and other use cases such as parsing, formatting and adding duration and periods.

Java LocalDateTime

Learn about the LocalDateTime class in Java, how to create its instances and other use cases such as parsing, formatting and adding duration and periods. 1. Overview java.time.LocalDateTime class, introduced in Java 8 Date Time API, represents a date and time object without a timezone often viewed as ‘year-month-day-hour-minute-second‘. It …

Java LocalTime

Learn to create and use the LocalTime class in Java. Learn how to create LocalTime, parse and format the LocalTime instances, including common operations such as adding or subtracting hours from a given time.

Java LocalDate

Learn about the LocalDate class in Java, how to create its instances and other use cases such as parsing, formatting and adding duration and periods.

Join or Append Stream Elements in Java

Learn to join a stream of strings with a delimiter, prefix, and suffix using Collectors.joining(), String.join(), and append elements using StringBuilder.

Sorting a Stream by Multiple Fields in Java

Java 8 example to sort stream of objects by multiple fields using comparators and Comparator.thenComparing() method. This method returns a lexicographic-order comparator with another comparator. It gives the same effect as SQL group by clause.

How to Sort a Stream in Java

Learn to sort stream of numbers and strings in ascending (natural order) and descending orders (reverse order) using Stream.sorted() method.

Java Collect Stream to List (with Examples)

Learn to convert stream to list using Collectors.toList() and Collectors.toCollection() APIs. This post contains multiple examples for collecting stream elements to list under different usecases.

Java Stream toArray() Example

Learn to convert stream to array using Stream.toArray() API. This post contains multiple examples for collecting stream elements to array under different usecases.

Java Stream noneMatch()

Java Stream noneMatch(predicate) is a short-circuiting terminal operation to check if no element in the stream matches the given predicate.

Java Stream allMatch()

Java Stream allMatch() is a short-circuiting terminal operation that is used to check if all the elements in the stream satisfy the provided predicate. 1. Stream allMatch() Method 1.1. Syntax Here predicate a non-interfering, stateless predicate to apply to all the elements of the stream. The allMatch() method returns always …

Java Stream anyMatch()

Java Stream anyMatch (Predicate predicate) is terminal-short-circuiting operation which is used to check if the stream contains any matching element with provided predicate.

Java Stream skip()

Java Stream skip(n) method returns a new stream consisting of the remaining elements of this stream, after the n elements have been skipped.

Java Stream limit()

We can use Stream.limit(long) to retrieve elements while they must not be greater than a certain maximum count. Java 8 Stream limit() example

Java Stream peek()

Java 8 Stream interface has peek(Consumer action) method which returns a new stream consists of all the elements of original stream after applying the method argument Consumer action.

Java Stream flatMap()

Learn to use Java Stream flatMap() method which is used to flatten a stream of collections to a stream of elements combined from all collections.

Java Stream map()

Learn to use Java Stream map() method which produces one output value of a different type ‘X’ for each input value of type ‘Y’.

Java Stream min()

Learn to use Stream min() method to select the smallest element in the stream according to the comparator provided in its argument.

Java Stream max()

Learn to use Java Stream max() method to select the largest element in the stream according to the comparator provided in its argument.

Negating a Predicate in Java

Java 8 predicate negate() returns a predicate that is the logical negation of this predicate. Java 11 introduced not() which is also the same.

Java Stream filter()

Learn to use Stream.filter(Predicate) method to traverse all the elements and filter all items which match a given condition through Predicate argument. 1. Stream filter() Method The stream() method syntax is as follows: Predicate is a functional interface and represents the condition to filter out the non-matching elements from the …

Java Stream forEachOrdered()

Learn to use Stream.forEachOrdered(Consumer action) method to traverse all the elements and performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order.

Java Stream forEach()

Learn to use Stream forEach(Consumer action) method to traverse all the elements of stream and performs an action for each element of this stream.

Creating Streams in Java

Learn to create Streams of primitives and objects in Java using some most popular ways. We will learn to create finite as well as infinite streams.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.