Instant isAfter() method in Java with Examples
isAfter() method of an Instant class is used to check if this instant is after the instant passed as parameter or not. This method returns a boolean value showing the same.
public boolean isAfter(Instant otherInstant)
Parameter: This method takes a parameter otherInstant which is the other instant to compare to this instant. It should not be null.
Returns: This method returns true if this instant is after the specified instant. Else it returns false.
Exception: This method throws NullPointerException if otherInstant passed as the parameter is null.
Below programs illustrate the isAfter() method:
Instance 1: 2018-12-30T19:34:50.630Z Instance 2: 2018-12-29T09:24:00.630Z Is Instant1 after Instant2: true
Instance 1: 2018-10-30T19:34:50.630Z Instance 2: 2018-11-27T04:52:08.970Z Is Instant1 after Instant2: false
Program 3: To show Exception thrown by isAfter()
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.