MonthDay query() method in Java with Examples Last Updated : 10 Jan, 2019 Comments Improve Suggest changes Like Article Like Report query() method of an MonthDay class used to query this MonthDay using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this MonthDay. Syntax: public <R> R query(TemporalQuery<R> query) Parameters: This method accepts only one parameter query which is the query to invoke. Return value: This method returns the query result, null may be returned. Exception: This method throws following Exceptions: DateTimeException - if unable to query . ArithmeticException - if numeric overflow occurs. Below programs illustrate the query() method: Program 1: Java // Java program to demonstrate // MonthDay.query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create MonthDay object MonthDay lt = MonthDay.parse("--12-09"); // apply query method of MonthDay class String value = lt.query( TemporalQueries.chronology()) .toString(); // print the result System.out.println("chronology value" + " for MonthDay is " + value); } } Output: chronology value for MonthDay is ISO Program 2: Showing if query did not found the required object then it returns null. Java // Java program to demonstrate // MonthDay.query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create MonthDay object MonthDay lt = MonthDay.parse("--12-07"); // apply query method of MonthDay class // print the result System.out.println("offset value" + " for MonthDay is " + lt.query( TemporalQueries.offset())); } } Output: offset value for MonthDay is null References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#query(java.time.temporal.TemporalQuery) Comment More infoAdvertise with us Next Article MonthDay query() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-MonthDay Practice Tags : Java Similar Reads MonthDay range() method in Java with Examples range() method of the MonthDay class used to get the ValueRange object which is the range of field in terms of the minimum and maximum values for the field passed as a parameter to this method. The method returns ValueRange object only for those fields which are supported by MonthDay object. So when 2 min read MonthDay with() Method in Java with Examples with(Month month) method of the MonthDay class used to alter the month-of-year of MonthDay object using month passed as a parameter and after that method returns the copy of altered MonthDay.If the day-of-month value is invalid for the specified month after altering operation, the day will be adjust 2 min read MonthDay get() method in Java with Examples The get() method of MonthDay class in Java gets the value of the specified field from this month-day as an int. Syntax: public int get(TemporalField field) Parameter: This method accepts a parameter field which specifies the field to get and not null. Returns: The function returns the value for the 2 min read MonthDay toString() Method in Java with Examples toString() method of the MonthDay class used to represents this month-day as a String like --08-23.The output will be in the format --MM-dd:Syntax: public String toString() Parameters: This method did not accepts any parameter.Return value: This method returns a String representation of this MonthDa 1 min read MonthDay from() method in Java with Examples The from() method of MonthDay class in Java obtains an instance of MonthDay from a temporal object. Syntax: public static MonthDay from(TemporalAccessor temporal) Parameter: This method accepts a parameter temporal which specifies the temporal object to convert which is not null. Returns: The functi 1 min read OffsetDateTime query() method in Java with Examples query() method of an OffsetDateTime class used to query this OffsetDateTime using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this OffsetDateTime. Syntax: public <R> R query(TemporalQuery<R> query) Pa 2 min read MonthDay atYear() method in Java with Examples The atYear() method of MonthDay class in Java combines this month-day with a year to create a LocalDate. Syntax: public LocalDate atYear(int year) Parameter: This method accepts a parameter year which specifies the year to use which is in range [MIN_YEAR, MAX_YEAR] Returns: The function returns the 1 min read Period ofMonths() method in Java with Examples The ofMonths() method of Period Class is used to obtain a period from given number of Months as parameter. This parameter is accepted in the form of integer. This method returns a Period with the given number of months. Syntax: public static Period ofMonths(int numberOfMonths) Parameters: This metho 2 min read MonthDay equals() method in Java with Examples The equals() method of MonthDay class in Java checks if this month-day is equal to another month-day. Syntax: public boolean equals(Object obj) Parameter: This method accepts a parameter obj which specifies if this month-day is equal to another month-day. Returns: The function returns true if this i 1 min read MonthDay format() method in Java with Examples The format() method of MonthDay class in Java formats this month-day using the specified formatter. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a parameter formatter which specifies the formatter to use and it is not null. Returns: The function returns th 1 min read Like