isBefore() method of an Instant class checks if this instant timeline position is before the instant passed as parameter or not. If this instant timeline position is before the instant passed as a parameter then the method will return true else false. The comparison is based on the time-line position of the instants.
public boolean isBefore(Instant otherInstant)
Parameter: This method takes a parameter otherInstant which is the other instant to compare to. It should not be null.
Returns: This method returns true if this instant is before the specified instant.
Exception: This method throws NullPointerException if otherInstant is null.
Below programs illustrate the isBefore() method:
Instance 1: 2018-12-30T09:24:54.630Z Instance 2: 2018-12-31T01:34:00.630Z Is Instant1 before Instant2: true
Instance 1: 2018-11-27T09:24:54.630Z Instance 2: 2018-11-27T04:55:36.127Z Is Instant1 before Instant2: false
Program 3: To show Exception thrown by isBefore()
Instance 1: 2018-10-30T19:34:50.630Z Instance 2: null Exception: java.lang.NullPointerException
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.