YearMonth isSupported(TemporalUnit) Method in Java with Examples
The isSupported(TemporalUnit) method of YearMonth class is used to Check if the specified TemporalUnit is supported by YearMonth class. Actually, this method checks if we can apply addition or subtraction operation using the passed unit to the specified unit this YearMonth. If false, then calling the plus(long, TemporalUnit) and minus methods will throw an exception.
The supported units of ChronoUnit(Temporalunit) are:
All other ChronoUnit instances will return false.
public boolean isSupported(TemporalUnit unit)
Parameters: This method accepts only one parameter unit which represents the TemporalUnit to check.
Return Value: This method returns a boolean value true if the unit is supported on this YearMonth, false if not.
Below programs illustrate the isSupported(TemporalUnit) method:
YearMonth :2017-08 MONTHS unit is supported by YearMonth class: true
YearMonth :2022-12 MILLENNIA unit is supported: true
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.